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: Wrapping Log4Net with a Facade - How to get the correct Location Information
Date Mon, 29 Aug 2005 15:06:35 GMT

The log4net config file can contain other configuration data, however it must be outside the
<log4net> element. For example:

<config>
  <your-config-data>
    ...
  </your-config-data>

  <log4net>
    ...
  </log4net>
</config>


log4net does not remember where the configuration file is, so you cannot ask log4net where
the configuration file is. If you are programmatically calling the Configure method passing
in the config file location then it should be trivial for you to parse your own config data
from the file. If you are configuring log4net using assembly attributes then you would need
to follow the same logic as in log4net to locate the config file.

Nicko

> -----Original Message-----
> From: Shireesh Thanneru [mailto:thanneru@yahoo.com] 
> Sent: 29 August 2005 05:17
> To: Log4NET User
> Subject: RE: Wrapping Log4Net with a Facade - How to get the 
> correct Location Information
> 
> Nicko,
> 
> Thanks...That worked like a charm and now I see the actual 
> location information.
> 
> While we are on the facade, I have one more question. For our 
> facade layer, we will have some configuration information 
> (similat to how log4net needs its config info) that will 
> configure our facade's behavior...for e.g. message size 
> limits for each log level, etc. I am wondering whether we can 
> have this config info in the same file that we have log4net's 
> configuration (log4net.config in our case) information and 
> how to get the updated values if this file gets updated. I am 
> trying to avoid two different config files (one for log4net 
> and one for our facade), but still be able to 
> configure/bootstrap our facade layer and reload the updated 
> config info if this file gets updated at run time. Please let 
> me know what would be a good approach for this.
> 
> Thanks,
> 
> Shireesh Thanneru
> 
> --- Nicko Cadell <nicko@neoworks.com> wrote:
> 
> > The log4net ILog / LogImpl types are a façade (also known 
> as wrapper 
> > or extension) around log4net. If you are creating your own 
> façade you 
> > need to do the same as the LogImpl class.
> > 
> > Rather than calling LogManager and wrapping the ILog objects you 
> > should call into log4net.Core.LoggerManager to get Loggers.
> > 
> > ILogger logger =
> > LoggerManager.GetLogger(Assembly.GetCallingAssembly(), 
> "loggername");
> > 
> > 
> > Then on the logger object use the Log method to inject the logging 
> > event.
> > 
> > logger.Log(thisDeclaringType, level, message, exceptionOrNull);
> > 
> > 
> > The thisDeclaringType parameter is the type of your façade object.
> > This is used when searching the call stack for the caller location 
> > information.
> > 
> > Cheers,
> > Nicko
> > 
> > > -----Original Message-----
> > > From: Shireesh Thanneru [mailto:thanneru@yahoo.com]
> > > Sent: 25 August 2005 01:08
> > > To: Log4NetUser
> > > Subject: Wrapping Log4Net with a Facade - How to get the correct 
> > > Location Information
> > > 
> > > We are wrapping Log4Net with a home grown Facade along 
> the lines of 
> > > sl4j. We are doing this basically for two reasons:
> > > to swap the underlying logger (for e.g. replacing log4net with 
> > > something else) and to provide additional functionality at the 
> > > Facade level (for example, enforcing size limits for log 
> messages, 
> > > logging additional info depending on the level, for e.g 
> COM+ context 
> > > info, etc). Everything is working fine so far, but when log4net 
> > > prints the loggingEvent.LocationInformation, it is printing the 
> > > Facade location/caller information instead of the actual 
> class that 
> > > is logging the message. What is the recommended way to solve this 
> > > problem and print the correct location information when we have a 
> > > wrapper facade on top of log4net?
> > > 
> > > Thanks,
> > > 
> > > Shireesh Thanneru
> > > 
> > > 
> > > 	
> > > 
> > 
> 
> 
> 

Mime
View raw message