logging-log4net-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nick Durcholz <NDUR...@e-farmcredit.com>
Subject RE: Change the log level programmatically?
Date Wed, 11 Feb 2009 15:01:27 GMT
There isn't a clean way to do this with the interfaces provided.  If you really MUST have this,
you could probably hack something up, but it would require breaking some of the abstractions
that the framework tries to enforce.  You could also try loading the config xml into memory,
modifying it using the dom, and then reconfiguring the entire heirarchy using log4net.Config.XmlConfigurator.Configure(ILoggerRepository
repository, XmlElement element).  I've never tried this, so can't really say what pitfalls
and 'gotchas' come along with doing that.

Why do you need to change the level of a logger at runtime in the first place?  There may
be a better way to accomplish the task at hand without doing that.


From: Eric Rose (erose) [mailto:erose@cisco.com] 
Sent: Wednesday, February 11, 2009 9:37 AM
To: Log4NET User
Subject: RE: Change the log level programmatically?



I sent this question a couple of weeks ago, but haven't heard any feedback from anyone...

Could someone offer some suggestions here, or let me know that this can't be done?!






From: Eric Rose (erose) 
Sent: Friday, January 30, 2009 10:22 PM
To: log4net-user@logging.apache.org
Subject: Change the log level programmatically?



Hopefully this is an easy question which has already been asked (and answered) before.

I searched online, but could not find a reasonable answer...


Is there a way to change the default log level of a logger via C# program control?


I don't need the setting to persist, so I don't want to have to change the XML config file
and re-read it.


In my C# code, I have a ILog variable that we use for all logging, defined as follows:


private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);


I'd like to be able to somehow be able to use that 'log' variable, and set it's log level
(INFO, WARN, ERROR, OFF, ALL, etc) to whatever I want in the code.



Any help or pointers to useful examples would be appreciated!







Eric Rose
Software Engineer
Product Development

erose@cisco.com <mailto:erose@cisco.com> 
Phone :(978) 936-1858

	Cisco Systems, Inc.
500 Beaver Brook Road
Boxborough, MA 01719

www.cisco.com <http://www.cisco.com> 





View raw message