Changing logging level in log4net xml
I've a c# 3.5 winforms desktop app running on production server.It uses log4net for logging.
The requirement is that the user should be able to switch the logging level at run time...for eg:if the level is switched to "INFO" level, then app shud write only info level logs. Also, the business does not want to change the log level by going on to prod server and editing the log4net xml file.
Which one of the following approaches would be ok for this?Or is there any other better approach? Have an "Admin" winform which will enable the user to change the log level. The user will be logging on to app from their desktop.
1.And then In the app, I can load log4net xml from the network path开发者_开发问答 using log4net api, save the changes with the new level provided from the UI and then re-instantiate the logger class with the new level.
or
2.Have 2 new tables in the backend....a look up table "A" with the level Ids and Names.And another table "B" with user name, current level id and date modified.
Update the level provided from UI screen in table B. Using .net's Sqlcachedependency, whenever the value in the table B changes,re-instantiate the logger class with the new level.
Thanks.
Perhaps if you go for the 1-st option it will be much easier.
You might want to copy log4net config file to the local user machine. Once user changed the level you save it locally to the xml. You can use this method to track changes in the log4net config
log4net.Config.XmlConfigurator.ConfigureAndWatch
Lastly, you will need to reinitialise the logger
By default, log4net hooks a file change notification on it's config file and automatically reconfigures when the file is updated. So, I'd think it would be the least work to have your UI hack the config file. I would think the easiest approach all around would be to put a little web app on the server with the app ronning on the server with a simple UI for changing the log level in the log4net xml config file.
精彩评论