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 Paul Cowan <Pa...@jkd.co.uk> on 2005/05/31 09:59:03 UTC

Calling method

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.GetCurrentMeth
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??

 

Thanks

 

Paul 


_____________________________________________________________________
VirusChecked for the Incepta Group plc
_____________________________________________________________________

Re: Calling method

Posted by Graham Innocent <gi...@parthenoncomputing.com>.
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.GetCurrentMethod().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

Re: Calling method

Posted by Frode Breimo <fr...@broadpark.no>.
Hi

I've only started looking at log4net myself and I'm using a similar 
approach. I started out with exactly the same solution as you describe, 
and of course I got the same result.

What I did was to add a GetLogger method to my Logger class, this takes 
a string parameter containing the name of the logger to return. Then you 
can use reflection in the actual method call, to pass the name of the 
calling class, like this:

    ILog log = 
Logger.GetLogger(MethodBase.GetCurrentMethod().DeclaringType));

If you don't want to configure a logger for each class, maybe creating 
one for each namespace could be an idea? This is what I did, passing the 
namespace of the calling class as a parameter:

    ILog log = 
Logger.GetLogger(MethodBase.GetCurrentMethod().DeclaringType.Namespace));

Hope this helps.

I wouldn't mind some feedback on the architecture of this approach though.


-Frode


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.GetCurrentMethod().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??
>
>  
>
> Thanks
>
>  
>
> Paul
>
>
> _____________________________________________________________________
> VirusChecked for the Incepta Group plc
> _____________________________________________________________________