开发者

How to switch on/off logging using Log4net

开发者 https://www.devze.com 2023-01-23 05:20 出处:网络
I have logged all my applications transaction using Log4net. Is there any way I can disable an开发者_StackOverflow中文版d enable logging from a common place without altering the code written for loggi

I have logged all my applications transaction using Log4net. Is there any way I can disable an开发者_StackOverflow中文版d enable logging from a common place without altering the code written for logging.


I assume you want to toggle logging in your running application through code. I did not try it but I think that calling the following method should disable logging:

LogManager.GetRepository().ResetConfiguration();

To re-enable logging you would call

XmlConfigurator.Configure();

(or one of the other methods of the XmlConfigurator).

However there seems to be an issue with calling the Configure method repeatedly. I do not know if this would be a problem for you, but at least I warned you...


You can turn them off by changing the log4net config file. Specifically change the appender's level or global level to "OFF" value. See here for details


Assuming I understand your question, from the FAQ: http://logging.apache.org/log4net/release/faq.html

How do I completely disable all logging at runtime?

Setting the Threshold on the Hierarchy to Level OFF will disable all logging from that Hierarchy. This can be done in the log4net configuration file by setting the "threshold" attribute on the log4net configuration element to "OFF". For example:

0

精彩评论

暂无评论...
验证码 换一张
取 消