> Thanks for the quick reply!!!!!! How about 2 more questions...?
>
> 1) I am using loglevel = log.Logger.Repository.Threshold.Name
> as the mechanism to get a logger's level. Is that the best
> way to get the level for a given logger?
That will give you the level for the whole repository not for the
logger.
You need to do:
((log4net.Repository.Hierarchy.Logger)log.Logger).Level.Name
The log4net API is optimised for the configurator rather than
programmatic configuration, this does mean that there is rather a lot of
casting required to do it programmatically.
> 2) Does it hurt (do bad things) to call the DOMConfigurator
> more than once? I have been whenever I started a logger
> (didn't mean to) but everything seems to be working.
Well it will hurt performance, but it is safe to reload the
configuration. You can even ask the DOMConfigurator to watch a file for
changes and reload the configuration automatically.
Cheers,
Nicko
>
> Once again, THANKS FOR THE QUICK REPLY!!!!!!
>
> Dave Witt
>
> ps. You and your group have done a wonderful job on this!!!!!!!!
>
>
>
>
> At 06:29 PM 9/26/2004, you wrote:
> >Dave,
> >
> > > Is there a method that allows me to set a logger level
> without going
> > > through the repository?
> >
> >You can set the Level property on the
> >log4net.Repository.Hierarchy.Logger object. You can do this
> in a number
> >of ways but the simplest is:
> >
> >log4net.Repository.Hierarchy.Logger logger =
> >((log4net.Repository.Hierarchy.Logger)log4net.LogManager.GetL
ogger("foo"
> >).Logger);
> >logger.Level = logger.Repository.LevelMap["DEBUG"];
> >
> >
> >This lets you set the level for an individual logger.
> >
> >
> > >
> > > 2) Is there a way to enable/disable appenders programmatically?
> >
> >Appenders have a Threshold level (or at least the
> AppenderSkeleton does
> >and appenders should be derived from that) that you can set to
> >Level.Off which will prevent any logging from occurring
> through that appender.
> >
> >log4net.Repository.Hierarchy.Logger logger =
> >((log4net.Repository.Hierarchy.Logger)log4net.LogManager.GetL
ogger("foo"
> >).Logger);
> >log4net.Appender.AppenderSkeleton appender =
> >(log4net.Appender.AppenderSkeleton)logger.GetAppender("myAppender");
> >appender.Threshold = Level.Off.
> >
> >
> >This will not shutdown the appender, e.g. the FileAppender
> will still
> >hold a write lock on the output file. You may want instead to remove
> >the appender from the Logger and close it.
> >
> >
> >log4net.Repository.Hierarchy.Logger logger =
> >((log4net.Repository.Hierarchy.Logger)log4net.LogManager.GetL
ogger("foo"
> >).Logger);
> >log4net.Appender.IAppender appender =
> logger.GetAppender("myAppender");
> >logger.RemoveAppender(appender); appender.Close();
> >
> >An appender cannot be revived after it has been closed.
> >
> >
> >Cheers,
> >Nicko
>
>
>
>