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:
精彩评论