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 Andreas HOELZLWIMMER <an...@racon.at> on 2012/06/01 09:36:23 UTC

ILog Wrapping

Hi,

I need to switch our logger to Log4Net in our application. I need to 
implement our personal logging interface, which means I need to wrap the 
Logger. The logger requires to display method name and namespace. With the 
"usual" way it always shows the method and namespace of the wrapper, not 
the method called. The option found on stackoverflow (
http://stackoverflow.com/questions/157232/how-to-log-methodname-when-wrapping-log4net
) does not help and I wanted to know if there is a way to log the correct 
method/namespace without having to go back in the call stack. Is there a 
best practise for wrapping ILog?

best regards,
Andreas



Der Austausch von Nachrichten mit o.a. Absender via e-mail dient ausschließlich Informationszwecken. Rechtsgeschäftliche Erklärungen dürfen über dieses Medium nicht ausgetauscht werden.

Correspondence with a.m. sender via e-mail is only for information purposes. This medium is not to be used for the exchange of legally-binding communications.

Antwort: Re: ILog Wrapping

Posted by Andreas HOELZLWIMMER <an...@racon.at>.
Hello,

I just changed my code to incorporate log4net.Core.ILogger instead of the 
comfort class log4net.ILog. With the Logger Wrapper Type always entered at 
the call of the log method, it now works. using only the ILog interface 
shows broken (as explained) behavior. I may be wrong, but this isn't 
supposed to happen this way, is it?






Andreas HOELZLWIMMER <an...@racon.at> 
04.06.2012 09:13
Bitte antworten an
"Log4NET User" <lo...@logging.apache.org>


An
"Log4NET User" <lo...@logging.apache.org>
Kopie

Thema
Antwort: Re: ILog Wrapping






The way I'm doing it now is by calling this line: 
private static readonly log4net.ILog log = 
            log4net.LogManager.GetLogger(System.Reflection.MethodBase
.GetCurrentMethod().DeclaringType); 

From what I see in your example, the important thing is to give the logger 
your current logging method Type, which is what I do. The difference is 
that instead of using the ILogger interface I use the ILog Interface, 
mostly because I wanted to use LogDebug, LogInfo, ... for comfort. Doing 
it with the given line, I expect it to work similarily to the example, 
namely 

private readonly static Type declaringType = typeof(Log4NetLogger); 
_logger.Log(declaringType, log4net.Core.Level.Info, message, e); 

Am I wrong to expect it to work in the same way? 




Ron Grabowski <ro...@yahoo.com> 
03.06.2012 01:11 

Bitte antworten an
"Log4NET User" <lo...@logging.apache.org>


An
Log4NET User <lo...@logging.apache.org> 
Kopie

Thema
Re: ILog Wrapping








The original poster specifically mentioned he did not want to have to walk 
to the call stack. Log4net internally walks the call stack so there's no 
need to walk it twice. 

The Stack Overflow article is correct. Here's another example: 

http://svn.apache.org/viewvc/ibatis/cs/ibatisnet-1/trunk/src/IBatisNet.Common.Logging.Log4Net/ 


The key concept is needing to pass in the Type of your wrapper to the 
actually log method so log4net knows to skip over that stack frame when 
its processing call information. 

From: Martin Milan <Ma...@enservegroup.com>
To: Log4NET User <lo...@logging.apache.org> 
Sent: Friday, June 1, 2012 4:13 AM
Subject: RE: ILog Wrapping 

Can you not walk the call stack until you come across a method that is not 
from the same namespace as your wrapper? 
  
Just an idea? 
  
  
From: Andreas HOELZLWIMMER [mailto:andreas.hoelzlwimmer@racon.at] 
Sent: 01 June 2012 08:36
To: log4net-user@logging.apache.org
Subject: ILog Wrapping 
  
Hi, 
I need to switch our logger to Log4Net in our application. I need to 
implement our personal logging interface, which means I need to wrap the 
Logger. The logger requires to display method name and namespace. With the 
"usual" way it always shows the method and namespace of the wrapper, not 
the method called. The option found on stackoverflow (
http://stackoverflow.com/questions/157232/how-to-log-methodname-when-wrapping-log4net
) does not help and I wanted to know if there is a way to log the correct 
method/namespace without having to go back in the call stack. Is there a 
best practise for wrapping ILog? 
best regards, 
Andreas 


Der Austausch von Nachrichten mit o.a. Absender via e-mail dient 
ausschließlich Informationszwecken. Rechtsgeschäftliche Erklärungen dürfen 
über dieses Medium nicht ausgetauscht werden.

Correspondence with a.m. sender via e-mail is only for information 
purposes. This medium is not to be used for the exchange of 
legally-binding communications. 
EnServe Group Limited ("EnServe"), registered in England and Wales with 
registration number 3250709.EnServe's registered office is at Hertsmere 
House, Shenley Road, Borehamwood, Herts, WD6 1TE, United Kingdom and a 
list of EnServe's subsidiaries and their registered particulars is 
available for inspection at this location. This email and any attachments 
to it are confidential and are intended solely for the use of the 
individual to whom it is addressed. Any views or opinions expressed are 
solely those of the author and do not necessarily represent those of 
EnServe or its subsidiaries. If you are not the intended recipient of this 
email, you must neither take any action based upon its contents, nor copy 
or show it to anyone. Please contact the sender if you believe you have 
received this email in error. 

This message has been scanned by Symantec Mail Security






Der Austausch von Nachrichten mit o.a. Absender via e-mail dient 
ausschließlich Informationszwecken. Rechtsgeschäftliche Erklärungen dürfen 
über dieses Medium nicht ausgetauscht werden.

Correspondence with a.m. sender via e-mail is only for information 
purposes. This medium is not to be used for the exchange of 
legally-binding communications.





Der Austausch von Nachrichten mit o.a. Absender via e-mail dient ausschließlich Informationszwecken. Rechtsgeschäftliche Erklärungen dürfen über dieses Medium nicht ausgetauscht werden.

Correspondence with a.m. sender via e-mail is only for information purposes. This medium is not to be used for the exchange of legally-binding communications.

Antwort: Re: ILog Wrapping

Posted by Andreas HOELZLWIMMER <an...@racon.at>.
The way I'm doing it now is by calling this line:
private static readonly log4net.ILog log = 
            log4net.LogManager.GetLogger(System.Reflection.MethodBase
.GetCurrentMethod().DeclaringType);

From what I see in your example, the important thing is to give the logger 
your current logging method Type, which is what I do. The difference is 
that instead of using the ILogger interface I use the ILog Interface, 
mostly because I wanted to use LogDebug, LogInfo, ... for comfort. Doing 
it with the given line, I expect it to work similarily to the example, 
namely

private readonly static Type declaringType = typeof(Log4NetLogger); 
_logger.Log(declaringType, log4net.Core.Level.Info, message, e); 

Am I wrong to expect it to work in the same way?





Ron Grabowski <ro...@yahoo.com> 
03.06.2012 01:11
Bitte antworten an
"Log4NET User" <lo...@logging.apache.org>


An
Log4NET User <lo...@logging.apache.org>
Kopie

Thema
Re: ILog Wrapping






The original poster specifically mentioned he did not want to have to walk 
to the call stack. Log4net internally walks the call stack so there's no 
need to walk it twice.

The Stack Overflow article is correct. Here's another example:

http://svn.apache.org/viewvc/ibatis/cs/ibatisnet-1/trunk/src/IBatisNet.Common.Logging.Log4Net/

The key concept is needing to pass in the Type of your wrapper to the 
actually log method so log4net knows to skip over that stack frame when 
its processing call information.

From: Martin Milan <Ma...@enservegroup.com>
To: Log4NET User <lo...@logging.apache.org> 
Sent: Friday, June 1, 2012 4:13 AM
Subject: RE: ILog Wrapping

Can you not walk the call stack until you come across a method that is not 
from the same namespace as your wrapper?
 
Just an idea?
 
 
From: Andreas HOELZLWIMMER [mailto:andreas.hoelzlwimmer@racon.at] 
Sent: 01 June 2012 08:36
To: log4net-user@logging.apache.org
Subject: ILog Wrapping
 
Hi, 
I need to switch our logger to Log4Net in our application. I need to 
implement our personal logging interface, which means I need to wrap the 
Logger. The logger requires to display method name and namespace. With the 
"usual" way it always shows the method and namespace of the wrapper, not 
the method called. The option found on stackoverflow (
http://stackoverflow.com/questions/157232/how-to-log-methodname-when-wrapping-log4net
) does not help and I wanted to know if there is a way to log the correct 
method/namespace without having to go back in the call stack. Is there a 
best practise for wrapping ILog? 
best regards, 
Andreas 


Der Austausch von Nachrichten mit o.a. Absender via e-mail dient 
ausschließlich Informationszwecken. Rechtsgeschäftliche Erklärungen dürfen 
über dieses Medium nicht ausgetauscht werden.

Correspondence with a.m. sender via e-mail is only for information 
purposes. This medium is not to be used for the exchange of 
legally-binding communications.
EnServe Group Limited ("EnServe"), registered in England and Wales with 
registration number 3250709.EnServe's registered office is at Hertsmere 
House, Shenley Road, Borehamwood, Herts, WD6 1TE, United Kingdom and a 
list of EnServe's subsidiaries and their registered particulars is 
available for inspection at this location. This email and any attachments 
to it are confidential and are intended solely for the use of the 
individual to whom it is addressed. Any views or opinions expressed are 
solely those of the author and do not necessarily represent those of 
EnServe or its subsidiaries. If you are not the intended recipient of this 
email, you must neither take any action based upon its contents, nor copy 
or show it to anyone. Please contact the sender if you believe you have 
received this email in error. 
This message has been scanned by Symantec Mail Security






Der Austausch von Nachrichten mit o.a. Absender via e-mail dient ausschließlich Informationszwecken. Rechtsgeschäftliche Erklärungen dürfen über dieses Medium nicht ausgetauscht werden.

Correspondence with a.m. sender via e-mail is only for information purposes. This medium is not to be used for the exchange of legally-binding communications.

Re: ILog Wrapping

Posted by Ron Grabowski <ro...@yahoo.com>.
The original poster specifically mentioned he did not want to have to walk to the call stack. Log4net internally walks the call stack so there's no need to walk it twice.

The Stack Overflow article is correct. Here's another example:

http://svn.apache.org/viewvc/ibatis/cs/ibatisnet-1/trunk/src/IBatisNet.Common.Logging.Log4Net/

The key concept is needing to pass in the Type of your wrapper to the actually log method so log4net knows to skip over that stack frame when its processing call information.



________________________________
 From: Martin Milan <Ma...@enservegroup.com>
To: Log4NET User <lo...@logging.apache.org> 
Sent: Friday, June 1, 2012 4:13 AM
Subject: RE: ILog Wrapping
 

Can you not walk the call stack until you come across a method that is not from the same namespace as your wrapper?
 
Just an idea…
 
 
From:Andreas HOELZLWIMMER [mailto:andreas.hoelzlwimmer@racon.at] 
Sent: 01 June 2012 08:36
To: log4net-user@logging.apache.org
Subject: ILog Wrapping
 
Hi, 
I need to switch our logger to Log4Net in our application. I need to implement our personal logging interface, which means I need to wrap the Logger. The logger requires to display method name and namespace. With the "usual" way it always shows the method and namespace of the wrapper, not the method called. The option found on stackoverflow (http://stackoverflow.com/questions/157232/how-to-log-methodname-when-wrapping-log4net) does not help and I wanted to know if there is a way to log the correct method/namespace without having to go back in the call stack. Is there a best practise for wrapping ILog? 
best regards, 
Andreas 


Der Austausch von Nachrichten mit o.a. Absender via e-mail dient ausschließlich Informationszwecken. Rechtsgeschäftliche Erklärungen dürfen über dieses Medium nicht ausgetauscht werden.

Correspondence with a.m. sender via e-mail is only for information purposes. This medium is not to be used for the exchange of legally-binding communications.Enserve Group Legal Disclaimer  
EnServe Group Limited ("EnServe"), registered in England and Wales with  registration number 3250709.EnServe's registered office is at Hertsmere House, Shenley Road, Borehamwood, Herts, WD6 1TE, United  Kingdom and a list of EnServe's subsidiaries and their registered particulars is available for inspection at this location. This  email and any attachments to it are confidential and are intended solely for the use of the individual to whom it is addressed.  Any views or opinions expressed are solely those of the author and do not necessarily represent those of EnServe or its  subsidiaries. If you are not the intended recipient of this email, you must neither take any action based upon its contents, nor  copy or show it to anyone. Please contact the sender if you believe you have received this email in error. 

This message has been scanned by Symantec Mail Security

RE: ILog Wrapping

Posted by Martin Milan <Ma...@enservegroup.com>.
Can you not walk the call stack until you come across a method that is not from the same namespace as your wrapper?

 

Just an idea…

 

 

From: Andreas HOELZLWIMMER [mailto:andreas.hoelzlwimmer@racon.at] 
Sent: 01 June 2012 08:36
To: log4net-user@logging.apache.org
Subject: ILog Wrapping

 

Hi, 

I need to switch our logger to Log4Net in our application. I need to implement our personal logging interface, which means I need to wrap the Logger. The logger requires to display method name and namespace. With the "usual" way it always shows the method and namespace of the wrapper, not the method called. The option found on stackoverflow (http://stackoverflow.com/questions/157232/how-to-log-methodname-when-wrapping-log4net <http://stackoverflow.com/questions/157232/how-to-log-methodname-when-wrapping-log4net> ) does not help and I wanted to know if there is a way to log the correct method/namespace without having to go back in the call stack. Is there a best practise for wrapping ILog? 

best regards, 

Andreas 


Der Austausch von Nachrichten mit o.a. Absender via e-mail dient ausschließlich Informationszwecken. Rechtsgeschäftliche Erklärungen dürfen über dieses Medium nicht ausgetauscht werden.

Correspondence with a.m. sender via e-mail is only for information purposes. This medium is not to be used for the exchange of legally-binding communications.


EnServe Group