Nicko,
I tried the code snipet you sent me (below) and it finds no appenders for each logger. Since the loggers are created programmatically (...getlogger("name")) and are not included in the .config file, is it possible that they don't have any appenders "attached" to them, but instead make use of the appenders through an "inheritance" path? I ask that because the appenders are working fine and the loggers are sending stuff to them, it is just that I can't fine them using the code you sent me.
Any ideas????
Thanks,
Dave
At 04:42 AM 9/27/2004, you wrote:
> Is it possible to get a list of appenders (independent of > loggers) and control their output (level = off...level = ???) > so as to be able to control them globally (for all loggers to > use), or do I have to do each appender for each logger in a > series of foreach loops?
Appenders are only available through their logger.
foreach(log4net.ILog log in log4net.LogManager.GetCurrentLoggers()) { foreach(log4net.Appender.IAppender appender in ((log4net.Repository.Hierarchy.Logger)log.Logger).Appenders) { do something with the appender... } }
It is possible to attach the same appender instance to more than one logger, therefore you may want to add all the appenders to a collection and unique them. Appender Names are not currently guaranteed to be unique.
Nicko
> > Thanks, > > Dave Witt > > ps. If you haven't figured it out yet, I am trying to build > a simple utility to manage the operation of loggers (levels) > and appenders (on/off) to help our support folks manage > log4net at a higher level than us as developers do :-) > > > > At 07:29 PM 9/26/2004, you wrote: > > > > > 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 > > > > > > > > > > > > > > > >
