I have logged all my applications transaction using Log4net. Is there any way I can disable and enable logging from a common place without altering the code written for logging.
If you are using a separate configuration file for log4net, do this: after following all the other setup instructions, make sure that u right click on the file in the visual studio solution explorer, select properties, expand the "Advanced" option group, set the "Copy To Output Directory" value as "Copy always".
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".
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With