Dynamic Watch Log4net Configure fix Watching Failed Problem

来源:互联网 发布:java定义json字符串 编辑:程序博客网 时间:2024/05/14 02:56

Problem:

Using Log4net to output logs.

  After the configure file is ready, we will add its reference to Project's AssemblyInfo.cs like this:

Log4net.Configure.XMLConfigure( Configure = File, Watch = True);

Then, Initial a logger by Log4Net.ILog.

If all are ready, we can use it for logging.


But, after i change Configre File's name and reset the info in Assembly.cs, log cannot be write again.

I have try many times, even simple the code and info in configuration.

None of them works.

Finally, the "Dynamic Watch" Help it.


Solution:

Abandon original watching approach. Do like this:

Add code before Logger instantiate:

FileInfo configureFileinfo = new Fileinfo( string fullpath of ConfigureFile);

Log4net.Config.XmlConfigurator.ConfigureAndWatch( configureFileinfo );

原创粉丝点击