修改或新增AppSetting节点
/// <summary>
/// 修改AppSettings中配置
/// </summary>
/// <param name="key">key值</param>
/// <param name="value">相应值</param>
public static bool SetConfigValue(string key, string value)
{
try
{
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
if (config.AppSettings.Settings[key] != null)
config.AppSettings.Settings[key].Value = value;
else
config.AppSettings.Settings.Add(key, value);
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("appSettings");
return true;
}
catch
{
return false;
}
}
/// <summary>
/// 获取AppSettings中某一节点值
/// </summary>
/// <param name="key"></param>
public static string GetConfigValue(string key)
{
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
if (config.AppSettings.Settings[key] != null)
return config.AppSettings.Settings[key].Value;
else return string.Empty;
} 获取AppSetting节点值

  

对log4Net 设置

<log4net>
<!--定义输出到文件中-->
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
<!--定义文件存放位置-->
<file value="log\\" />
<appendToFile value="true" />
<rollingStyle value="Date" />
<datePattern value="yyyyMMdd'.txt'" />
<staticLogFileName value="false" />
<param name="MaxSizeRollBackups" value="100" />
<layout type="log4net.Layout.PatternLayout">
<!--每条日志末尾的文字说明-->
<!--输出格式-->
<!--样例:2008-03-26 13:42:32,111 [10] INFO Log4NetDemo.MainClass [(null)] - info-->
<!--<conversionPattern value="%newline %n记录时间:%date %n线程ID:[%thread] %n日志级别: %-5level %n出错类:%logger property: [%property{NDC}] - %n错误描述:%message%newline %n"/>-->
<conversionPattern value="%n记录时间:%date %n错误描述:%message %n" />
</layout>
</appender>
<root>
<level value="ALL" />
<!--文件形式记录日志-->
<appender-ref ref="RollingLogFileAppender" />
</root>
</log4net>

  

  public static void WriteLog(Type t, Exception ex)
{
ILog log = LogManager.GetLogger(t);
log.Error("Error", ex);
} public static void WriteLog(Type t, string msg)
{
ILog log = LogManager.GetLogger(t);
log.Error(msg);
}

  

在写操作日志时,要注意,需要在命名空间上加一句[assembly: XmlConfigurator(Watch = true)]

app.config中的值获取及设置 以及对log4net配置的更多相关文章

  1. .net里面<app.config>中value值不能填写特殊符号问题

    配置app.config或web.config的时候,经常要填写value值, 但是value值不能包含特殊字符,需要转义, 分享一下转义字符 App.config 实际上是 xml 文件,在标准 x ...

  2. VS动态修改App.config中遇到的坑(宿主进程问题)

    昨天遇到了很奇怪的一个bug,具体描述如下: 这个系统是c/s架构的针对多个工厂做的资材管理系统,由于有很多个工厂,每个工厂都有自己的服务器.所以需要动态的改变连接字符串去链接不同的服务器. 由于这个 ...

  3. 在Web.config或App.config中的添加自定义配置

    .Net中的System.Configuration命名空间为我们在web.config或者app.config中自定义配置提供了完美的支持.最近看到一些项目中还在自定义xml文件做程序的配置,所以忍 ...

  4. winform程序读取和改写配置文件App.config元素的值

    winform程序读取和改写配置文件App.config元素的值 2016-05-16 17:49 by newbirth, 2412 阅读, 0 评论, 收藏, 编辑 1 2 3 4 5 6 7 & ...

  5. 在Web.config或App.config中的添加自定义配置 <转>

        .Net中的System.Configuration命名空间为我们在web.config或者app.config中自定义配置提供了完美的支持.最近看到一些项目中还在自定义xml文件做程序的配置 ...

  6. log4net日志在app.config中assembly不起作用

    log4net 1.2.15.0日志在app.config中assembly不起作用,必须 1.手动调用方法log4net.Config.XmlConfigurator.Configure()来初始化 ...

  7. C#读写app.config中的数据

    C#读写app.config中的数据 读语句: String str = ConfigurationManager.AppSettings["DemoKey"]; 写语句: Con ...

  8. winform中读取App.config中数据连接字符串

    1.首先要在工程引用中导入System.Configuration.dll文件的引用. 2.通过System.Configuration.ConfigurationManager.Connection ...

  9. C#中怎样获取默认配置文件App.config中配置的键值对内容

    场景 在新建一个程序后,项目中会有一个默认配置文件App.config 一般会将一些配置文件信息,比如连接数据库的字符串等信息存在此配置文件中. 怎样在代码中获取自己配置的键值对信息. 注: 博客主页 ...

随机推荐

  1. 洛谷 P1211 [USACO1.3]牛式 Prime Cryptarithm

    P1211 [USACO1.3]牛式 Prime Cryptarithm 题目描述 下面是一个乘法竖式,如果用我们给定的那n个数字来取代*,可以使式子成立的话,我们就叫这个式子牛式. *** x ** ...

  2. 在线java反编译服务

    大家是否遇到过有java class文件,却没有java源码的苦恼.近期findmaven.net提供了在线java反编译服务http://www.findmaven.net/decompile_cn ...

  3. 从数据表中随机抽取n条数据有哪几种方法(join实现可以先查数据然后再拼接)

    从数据表中随机抽取n条数据有哪几种方法(join实现可以先查数据然后再拼接) 一.总结 一句话总结:最好的是这个:"SELECT * FROM table WHERE id >= (( ...

  4. JS学习笔记 - 自定义右键菜单、文本框只能输入数字

    <script> // 事件总共有2个部分, //1.点击鼠标右键的表现 oncontextmenu 2.点击鼠标左键的表现(即普通点击onclick) // 点击右键,div位置定位到鼠 ...

  5. 10.5 android输入系统_Reader线程_使用EventHub读取事件和核心类及配置文件_实验_分析

    4. Reader线程_使用EventHub读取事件 使用inotify监测/dev/input下文件的创建和删除 使用epoll监测有无数据上报 细节: a.fd1 = inotify_init(& ...

  6. 再谈ITFriend网站的定位

    在网站开发阶段.内部测试阶段.公开测试阶段,让诸多好友和网友,参与了我们的网站ITFriend的体验和测试.其中,大家非常关心,我们的网站是干什么的.在我们不做任何解释的情况下,有的网站认为ITFri ...

  7. UVA Bandwidth

    题目例如以下: Bandwidth  Given a graph (V,E) where V is a set of nodes and E is a set of arcsin VxV, and a ...

  8. WCF REST 基础教程

    概述 Representational State Transfer(REST)是Roy Fielding博士在2000年他的博士论文中提出来的一种软件架构风格. 因此REST是设计风格而不是标准,R ...

  9. 7、linux之定时器

    (1) 一个timer_list 结构体的实例对应一个定时器,其定义如下: struct timer_list { struct list_head entry, /*定时器列表*/ unsigned ...

  10. [React] Use React.cloneElement to Modify and Add Additional Properties to React Children

    In this lesson we'll show how to use React.cloneElement to add additional properties to the children ...