2

I basically have the same question as

log4net only works when XmlConfigurator.Configure() is called

However, I couldn't comment there as I don't have any reputation (just signed up).

Thanks for any helpful comments. If I do anything wrong here, please advise. Thank you very much. Bernd

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:

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)

I configured it via XML:

<?xml version="1.0" encoding="utf-8" ?>
<log4net>  
  <appender name="RollingFile" type="log4net.Appender.RollingFileAppender">
    <file value="Logs/debug.log" />
    <encoding value="utf-8" />
    <appendToFile value="true" />
    <maximumFileSize value="10MB" />
    <maxSizeRollBackups value="2" />
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%date [%thread] %-5level (%class#%method:%line):%message%newline" />
    </layout>
  </appender>
  <root>
    <level value="DEBUG" />    
    <appender-ref ref="RollingFile" />
  </root>
</log4net>

My web service looks like this:

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");
    }
}

Hope this is quite sufficient. The LoggingUtil- class basically looks like this:

private const String Log4NetConfigurationFilePath = "log4net-config.xml"; //real path looks somewhat different
public static void InitializeLogging()
{    
  XmlConfigurator.Configure(new FileInfo(Log4NetConfigurationFilePath));     
}

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?

Daniel Steinmann
  • 2,119
  • 2
  • 15
  • 25
Bernd
  • 123
  • 5
  • 1
    Show how you configure, initialize and call log4net. – CodeCaster Jan 07 '14 at 16:27
  • Thanks for commenting. I updated the post. Hope this is precise enough. – Bernd Jan 08 '14 at 11:13
  • [What version are you using, and do you use dynamic methods](https://issues.apache.org/jira/browse/LOG4NET-393)? Update to at least version 1.2.13, as they claim to have fixed that issue. – CodeCaster Jan 08 '14 at 11:20
  • 1
    I'm using 1.2.12 and will try and update. I don't use dynamic methods. Actually, this is just plain Out-of-the-box VS web service. However, Microsoft might in the back ground. I will let you know about the update. – Bernd Jan 08 '14 at 11:38
  • Updated to Version [1.2.13] or 2.0.3 respectively (I don't know why there are 2 version numbers for the same version). This fixed the issue. @CodeCaster: Thank you very much. If you add your contribution as answer I'm happy to mark my question as solved. – Bernd Jan 08 '14 at 12:37

1 Answers1

7

As explained in LOG4NET-393, this error occurs when there is a dynamic method in the call chain.

There they claim to have this error fixed in versions > 1.2.12.

Daniel Steinmann
  • 2,119
  • 2
  • 15
  • 25
CodeCaster
  • 147,647
  • 23
  • 218
  • 272
  • 2
    Sorry I can't vote this up as my reputation doesn't suffice. Maybe someone else will have a similar problem and get you some credit. – Bernd Jan 08 '14 at 13:11