开发者

Using log4net in .net windows application

开发者 https://www.devze.com 2023-02-26 18:48 出处:网络
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.

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.


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.


Using

[assembly: log4net.Config.XmlConfigurator(Watch=true)]

may work, according to the documentation


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号