title: Log4net in a web service
body: <p>I basically have the same question as </p>
  
  <p><a href="https://stackoverflow.com/q/16766236/3169560">log4net only works when XmlConfigurator.Configure() is called</a></p>
  
  <p>However, I couldn't comment there as I don't have any reputation (just signed up). </p>
  
  <p>Thanks for any helpful comments. 
  If I do anything wrong here, please advise. 
  Thank you very much. Bernd</p>
  
  <p>Update: 
  Thanks for constructive hints. I've have made some progress and therefore will explain in more detail: 
  I use log4net within a (VS generated C# web service). I do get the debug information in the debug file, however within VS (2012) I do get the message for every logging call: </p>
  
  <pre><code>log4net:ERROR An exception ocurred while retreiving stack frame information.
  System.NullReferenceException: Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.
       bei log4net.Core.StackFrameItem..ctor(StackFrame frame)
  </code></pre>
  
  <p>I configured it via XML: </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;log4net&gt;  
    &lt;appender name="RollingFile" type="log4net.Appender.RollingFileAppender"&gt;
      &lt;file value="Logs/debug.log" /&gt;
      &lt;encoding value="utf-8" /&gt;
      &lt;appendToFile value="true" /&gt;
      &lt;maximumFileSize value="10MB" /&gt;
      &lt;maxSizeRollBackups value="2" /&gt;
      &lt;layout type="log4net.Layout.PatternLayout"&gt;
        &lt;conversionPattern value="%date [%thread] %-5level (%class#%method:%line):%message%newline" /&gt;
      &lt;/layout&gt;
    &lt;/appender&gt;
    &lt;root&gt;
      &lt;level value="DEBUG" /&gt;    
      &lt;appender-ref ref="RollingFile" /&gt;
    &lt;/root&gt;
  &lt;/log4net&gt;
  </code></pre>
  
  <p>My web service looks like this: </p>
  
  <pre><code>public class ObjectInfo : IObjectInfo
  {    
      private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  
  
  
      public void DoWork()        {
        Logging.LoggingUtil.InitializeLogging();
        log.Debug("Some message");
      }
  }
  </code></pre>
  
  <p>Hope this is quite sufficient. The LoggingUtil- class basically looks like this: </p>
  
  <pre><code>private const String Log4NetConfigurationFilePath = "log4net-config.xml"; //real path looks somewhat different
  public static void InitializeLogging()
  {    
    XmlConfigurator.Configure(new FileInfo(Log4NetConfigurationFilePath));     
  }
  </code></pre>
  
  <p>I wonder, if the problem is that the stack trace cannot be found out within Cassine as Microsoft doesn't allow this in order to protect their implementation of the web service?</p>