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 <[email protected]>
03.06.2012 01:11
Bitte antworten an
"Log4NET User" <[email protected]>
An
Log4NET User <[email protected]>
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 <[email protected]>
To: Log4NET User <[email protected]>
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:[email protected]]
Sent: 01 June 2012 08:36
To: [email protected]
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.