I have a project I am working on using log4net, and it works great, but I want to know if i can override the XML configuration for the root ‘level’ attribute for the logging when in debug and release.
Currently my root configuration looks like:
<root> <level value='WARN'/> <appender-ref ref='LogFileAppender'/> <appender-ref ref='DebugAppender'/> </root>
And in my web applications Global.asax class, I was thinking I could wrap something in a
protected override void Application_Start(object sender, EventArgs e) { base.Application_Start(sender, e); XmlConfigurator.Configure(); #if DEBUG //Change logging level to DEBUG #endif }
To change the root logging level to debug when the solution is built in debug.
Is this possible, is my idea a best-practises type soltuion to what I want, and how would I do it (or how would you do it better)?
I do the oposite, in debug mode I use the developer configurations which is better for filtering the relevant messages for me; and in release mode, I lock the level to WARN to prevent a user wants to hack my code (he could use tons of other ways, but this is a 5 seconds trick):