David, 

The <root> logger is not actually called "Root". In fact it cannot be
looked up using the LogManager.GetLogger("") call. Because loggers are
created on demand if you do call LogManager.GetLogger("Root") then you
will get back a new logger called Root but this is not the <root>
logger. To configure this "Root" logger you would use:

<logger name="Root">
  ...
</logger>

Ok so how do we get the real <root> logger?

log4net.Repository.Hierarchy.Hierarchy h =
(log4net.Repository.Hierarchy.Hierarchy)log4net.LogManager.GetLoggerRepo
sitory();
log4net.Repository.Hierarchy.Logger rootLogger = h.Root;

Then from there you can call GetAppender to lookup your ConsoleAppender.

Nicko

PS. I promise this will be easier in future.


> -----Original Message-----
> From: David B. Witt [mailto:[EMAIL PROTECTED] 
> Sent: 13 October 2004 16:58
> To: [email protected]
> Subject: Appender Levels
> 
> 
> Nicko,
> 
> Sorry to keep being a pest, but I tried the code snipet you 
> sent in the previous entry and it doesn't seem to work.  The 
> appender does not get set to anything, so the 
> appender.Threshold = Level.Off will generate an exception.
> 
> Here is the code you sent ...
> 
> log4net.Repository.Hierarchy.Logger logger = 
> ((log4net.Repository.Hierarchy.Logger)log4net.LogManager.GetLo
> gger("foo"
> ).Logger);
> log4net.Appender.AppenderSkeleton appender = 
> (log4net.Appender.AppenderSkeleton)logger.GetAppender("myAppender");
> appender.Threshold = Level.Off.
> 
> I have a ConsoleAppender defined, so I used "ConsoleAppender" 
> for "myAppender" and "Root" instead of "foo" when getting the logger.
> 
> As a reminder, I would like to be able to set the levels of 
> appenders programatically.  They start off as DEBUG, but I 
> would like to be able to change their levels as the program runs.
> 
> 
> I have gotten a list of all the Appenders (including those of 
> "Root") and can display their current levels, but cannot seem 
> to figure out how to change their levels.
> 
> THANKS AGAIN for all your help!!!!!
> 
> Dave
> 
> ps.  If I am being stupid here, please let me know.  I seem 
> to have a brain cramp around this.
> 
> 
> 
> 

Reply via email to