加载使用:
code
var log4net_config=path.combine(path.getdirectoryname(gettype().assembly.location),log4net.xml);
xmlconfigurator.configure(newfileinfo(log4net_config));
检视过整个配置之后,发现这个nuget来的配置文件有些地方出现纰漏:
其一是文件名称,log4net.xml并不是那么好用的,因为log4net自己也会生成一个同名的文件,如果顽固的使用xml文件,那么你需要配合第二点,并确保输出目录中的这个文件确实是配置文件,个人建议改成log4net.config更为妥当;
其二是项目中该文件属性,复制到输出目录需要设置成始终复制或较新复制,生成操作更应该不是无,请选择内容;
按照上面的修改配置文件之后,使用下面的代码加载后,log4net又活过来了。
code
var log4net_config=path.combine(path.getdirectoryname(gettype().assembly.location),log4net.config);// here is diff.
xmlconfigurator.configure(newfileinfo(log4net_config));
当然,为了简单,你也可以在assemblyinfo.cs中使用:
code
// 注意:是在assemblyinfo.cs文件中添加
[assembly:log4net.config.xmlconfigurator(configfile=log4net.config,watch=true)];
恩,就这样,log4net又能和我们一起愉快的玩耍了。
免费领取兄弟连it教育原创linux运维工程师视频/细说linux教程,详情咨询官网客服:http://www.lampbrother.net/linux/
学php、linux、html5、ui、android等视频教程(课件+笔记+视频)!联系q2430675018