You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4net-user@logging.apache.org by Nicko Cadell <ni...@neoworks.com> on 2005/06/02 21:12:50 UTC

RE: Calling method

Paul,

You are explicitly asking for the logger called
'Jkd.Vor.Utilities.Logger' and using that one logger instance. The use
of:

System.Reflection.MethodBase.GetCurrentMethod().DeclaringType

Is a convenience if you want to copy the same boilerplate code into each
class, however it is just equivalent to pass in the name of the class as
a string.

If you want to have a centralised log factory that returns loggers named
with the name of the previous entry on the call stack then you can write
something that will do that, however it will impose a severe performance
penalty on looking up a logger. I would not recommend doing so unless
you have a very specific issue that cannot be solved another way.

Is there a specific reason why you don't want to define a logger for
each class?

You can configure log4net to attempt to extract the calling method name
and type for each logging event, however this is not guaranteed to work
accurately as the runtime JIT may optimise away methods. This feature is
distinct from the logger name.

Nicko

> -----Original Message-----
> From: Paul Cowan [mailto:Paul.Cowan@jkd.co.uk] 
> Sent: 31 May 2005 10:38
> To: Log4NET User; gi@parthenoncomputing.com
> Subject: RE: Calling method
> 
> But I'm sure there is a way of doing this without defining a 
> logger in each class.  Somehow be able to drill down into the 
> call stack.
> 
> 
> 
> -----Original Message-----
> From: Graham Innocent [mailto:gi@parthenoncomputing.com]
> Sent: 31 May 2005 10:38
> To: Log4NET User
> Subject: Re: Calling method
> 
> Paul Cowan wrote:
> > 
> > 
> > Hi all,
> > 
> >  
> > 
> > I have my log4net functionality wrapped up in a logging 
> component, I 
> > have my logger declare like so:
> > 
> >  
> > 
> > namespace Jkd.Vor.Utilities
> > 
> > {
> > 
> >       public class Logger
> > 
> >       {
> > 
> > private static log4net.ILog log =
> >
> log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetC
> urrentMeth
> od().DeclaringType); 
> > 
> > 
> >       }
> > 
> > }
> > 
> >  
> > 
> > The question I have is, whenever I log, the logger field in 
> Sql Server
> 
> > or the source in the event log is always:
> > 
> >  
> > 
> > Jkd.Vor.Utilities.Logger,
> > 
> >  
> > 
> > Say Jkd.Vor.ClassA actually called the logger, how can I get the
> logger 
> > field or the source field to say Jkd.Vor.ClassA, that is 
> how would I 
> > declare my logger to return this??
> > 
> 
> That's because you have all logging being done by the logger 
> defined for
> 
> Jkd.Vor.Utilities.Logger. You could define a logger for each 
> class using
> 
> GetLogger(typeof(<class being logged>))
> 
> 
> -- 
> Graham Innocent, Business Development       Parthenon Computing
> +44-1865-811184                  		http://www.parthcomp.com
> 
> _____________________________________________________________________
> VirusChecked for the Incepta Group plc
> _____________________________________________________________________
> 
> 
> _____________________________________________________________________
> VirusChecked for the Incepta Group plc
> _____________________________________________________________________
> 
>