I’m trying to create a setup in my ASP.NET website that allows me to enable/disable logging while the application is running at any point. I figure some of you have already done such a thing.
Here’s the gist of what i’m trying to do:
if(ShouldBeLogging)
logger.Info("helloooooo there");
So how would you set up the boolean value ShouldBeLogging to be able to be turned on/off while the website is running without getting any serious performance drawbacks(seeing how its going to be accessed frequently)?
I was thinking about putting something in the web.config, but wouldn’t a change to that kick my user sessions if i wanted to turn it on?
Thanks!
I decided to go with log4net which supports this exact functionality. You can put a line in your assemblyinfo.cs like:
which will tell it to watch the config file for changes. then you can set the level node in the config xml at any time during the program’s execution and the logging will be turned on/off, as long as you’re using the following checks in your code:
see http://logging.apache.org/log4net/release/manual/internals.html for more info.