logging-log4net-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nicko Cadell" <ni...@neoworks.com>
Subject RE: Log4Net API to get appender config properties
Date Wed, 08 Dec 2004 15:03:41 GMT
Oliver,

> >  log4net.Repository.Hierarchy.Hierarchy h = 
> >(log4net.Repository.Hierarchy.Hierarchy)log4net.LogManager.Ge
> tLoggerRepository();
> >  
> >
> Why do you assume that this ILoggerRepository is really a Hierarchy?

Currently the only implementation of the ILoggerRepository interface is
Hierarchy. Other implementations may have been developed by you or 3rd
party developers. The only way to get to the root logger is to cast to
the Hierarchy type and use the Root property.

As with all sample code the error checking is left as an exercise for
the reader.


> 
> >  appenders.AddRange(h.Root.Appenders);
> >
> >  foreach(log4net.Repository.Hierarchy.Logger logger in
> >h.GetCurrentLoggers())
> >  
> >
> Why do you assume that this ILog is really a Logger?

The Hierarchy.GetCurrentLoggers method can only return
log4net.Repository.Hierarchy.Logger instances therefore this should be a
safe thing to do. A more cautious approach would be to get the results
as an ILogger array (the return type from Hierarchy.GetCurrentLoggers)
and then test if these can be cast to IAppenderAttachable and then use
the IAppenderAttachable.Appenders property to retrieve the appender.

 
> I usually tend to be quite careful with libraries written by 
> other people when interfaces are in use. I assume that 
> interfaces have been used for a reason, that reason being 
> that it's not safe to assume that the actual object is always 
> of some specific class type. Why else would I be using 
> interfaces? In log4net, have interfaces been used for some 
> other reason so it's safe to make assumptions about the 
> classes implementing them?

Interfaces have been used to allow alternative implementations to be
substituted. At the current time there are no alternative
implementations of ILoggerRepostiroy and ILogger in the log4net source,
however you could supply your own alternative implementation, which
would break the sample.

I have added a GetAppenders method to the ILoggerRepostiroy interface in
CVS. This means that it will be the implementers responsibility to
locate and return the appenders in a robust way. This should solve the
issues you raised in future, however at the moment you need to do
something like the sample, hopefully you will find it useful.

Cheers,
Nicko

------------
Nicko Cadell
log4net development
http://logging.apache.org/log4net

Mime
View raw message