There is not a good way to programmatically control log4net. I wanted to build a page for my web app that allowed the sysadmin to control the logging output at runtime through a nice GUI, but there's no real way to do this.
The only way, which is not preferable, in my opinion, but there is no choice, is to set up the DOMConfigurator to point to a config file and when you wish to change something at run time, shut down log4net (there are a few steps to this), write out a new config file, and reinitialize log4net. I've had all sorts of problems with the automatic configuration. Sometimes the file is locked, sometimes it doesn't pick up changes, sometimes it doesn't seem to reinitialize everything (some loggers don't get the update). The only way I've been able to reliably affect change is to shut the whole logging works down through a series of procedures, write out the new config file then bring the whole thing back up. This is obviously bad for a web app because: a.) you lose log messages during this time unless you block the entire app (which is worse?) b.) you must synchronize writing to the file in the case where more than one sysadmin happens to be fiddling with the logging configuration c.) You have to code the part about writing out the file defensively because sometimes the file seems to be locked (by log4net? I'm not sure). I had to write a loop to keep retrying the file write until it goes through or eventually give up after 10 or so retries (it usually succeeds in 2-3 if not the first time). The most frustrating part of this is that log4net ALMOST has the ability to be programmatically configured. It's about 75% the way there, but there are a few key things you cannot do programmatically and so you have to give up and do the file-mangling hack. </rant> -Chad -----Original Message----- From: David Elliott [mailto:[EMAIL PROTECTED] Sent: Tuesday, May 25, 2004 9:19 AM To: [email protected] Subject: Question on SDK Classes I like taking programs apart in order to understand how they work. There aren't alot of examples for me to disect, so I must ask some of these questions. If anyone has more advanced demos they would care to share, I would appreciate it. I have Looked through the SDK and have traversed the ILog structure that is returned from the LogManager.GetLogger() method using intellisense. Are the majority of these SDK classes primarily if you are creating a custom logger/appender/repository? In traversing the ILog structure, there doesn't seem to be a way to affect the logger once it is created, other than modifying the XML file. For instance, programatically changing the output format of the date from ABS_TIME_DATE_FORMAT to ISO8601_DATE_FORMAT. Am I wrong? Don't know why I would want to do this. Just trying to find out everything I can. Thanks, Dave _________________________________________________________________ Get 200+ ad-free, high-fidelity stations and LIVE Major League Baseball Gameday Audio! http://radio.msn.click-url.com/go/onm00200491ave/direct/01/
