Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Please note that <code>frame.GetMethod().DeclaringType</code> can return <code>null</code>: sometime ago I faced with this problem only on <strong>release build</strong> of my application using <a href="http://nlog-project.org/" rel="nofollow">NLog logger</a> (<code>GetCurrentClassLogger</code>). Can't remember exactly the case. By the way, it is <a href="http://nlog.codeplex.com/workitem/6999" rel="nofollow">known issue</a>.</p> <p>There is an interesting trick in <a href="http://logging.apache.org/log4net/" rel="nofollow">Apache log4net</a> which allows to detect the caller info (class, method, etc.).</p> <p>Please take a look at:</p> <ol> <li><p><code>LocationInfo</code> class (<a href="http://svn.apache.org/viewvc/logging/log4net/trunk/src/log4net/Core/LocationInfo.cs?view=markup" rel="nofollow">source</a>) - the internal representation of caller location information.</p> <pre><code>public class LocationInfo { ... public LocationInfo(Type callerStackBoundaryDeclaringType) { // Here is the trick. See the implementation details here. } ... } </code></pre></li> <li><p><code>LogImpl</code> class (<a href="http://svn.apache.org/viewvc/logging/log4net/trunk/src/log4net/Core/LogImpl.cs?view=markup" rel="nofollow">source</a>) - the logger implementation class - wrapper around ILogger interface - to do the trick <strong>it must not be subclassed</strong>!</p> <pre><code>public class LogImpl : LoggerWrapperImpl, ILog { ... public LogImpl(ILogger logger) : base(logger) { ... } /// &lt;summary&gt; /// The fully qualified name of this declaring type not the type of any subclass. /// &lt;/summary&gt; private readonly static Type ThisDeclaringType = typeof(LogImpl); virtual public void Error(object message, Exception exception) { Logger.Log(ThisDeclaringType, m_levelError, message, exception); } ... } </code></pre></li> </ol>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload