Reputation: 739
We are using log4Net to log messages into files and database from our .Net 3.5 windows application.
The winforms application is deployed on to production environment and is up and running. Before the deployment, the level node attribute value is set to "ALL".
<level value="ALL"/>
While the application is running, I need to change the level to say "ERROR" and save the xml.And then, the log4net should log only "error" type messages in the log. How do i achieve this using log4net? If not feasible,any other approach please?
Thanks.
Upvotes: 2
Views: 3133
Reputation: 29755
By default, if you keep your log4net configuration in a separate file (as opposed to in the app.config file) you can update that file and the application will immediately change what level it logs information thanks to the XmlConfigurator in log4net.
If you'd like to update the logging level dynamically from within your application, there's a simple way of doing that thanks to the LINQ to XML capabilities from .Net 3.5+. I've written a blog post outlining how to do that here.
Upvotes: 3
Reputation: 74300
Using
[assembly: log4net.Config.XmlConfigurator(Watch=true)]
may work, according to the documentation
Upvotes: 2
Reputation: 1077
In the application you would need to have a filewatcher on the config file, then re-run the log4net initialisation on change of config file.
Upvotes: 0