locked
log4net file not written RRS feed

  • Question

  • Windows 7 (64-bit), VS 2008 SP1, WPF 3.0, Log4net 1.2.10
    I have a UserControl Project
    I want to include the log4net logging facility.
    My problem is that I cannot see an output XML file with the logging information.
    I suspect that my problem is elementary, as I do not see a forum post similar to my issue.

    Here is the relevant portion of my UserControl Prioject app.config -
    <configSections>
        <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,Log4net"/>
      </configSections>
      <log4net>
        <appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
          <file value="log.xml" />
          <appendToFile value="true" />
          <datePattern value="yyyyMMdd-HHmm" />
          <rollingStyle value="Date" />
          <layout type="log4net.Layout.XmlLayoutSchemaLog4j">
            <locationInfo value="true" />
          </layout>
        </appender>
        <root>
          <level value="DEBUG" />
          <appender-ref ref="RollingFileAppender" />
        </root>
      </log4net>

    Here are the relevant lines from my UserControl class file -

    public partial class Publisher : UserControl
      {
        // protected static readonly ILog log = LogManager.GetLogger(typeof(Publisher));
        protected static readonly ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

    From the Publisher constructor:
    log4net.Config.XmlConfigurator.Configure();
    log.Debug("log4met test message, Debug level.");
    log.Info("log4met test message, Info level.");
    log.Warn("log4met test message, Warn level.");
    log.Error("log4met test message, Error level.");
    log.Fatal("log4met test message, Fatal level.");

    I cannot find a log.xml file anywhere. What am I doing wrong?

    • Moved by Jay_WangMicrosoft employee Thursday, April 15, 2010 2:12 AM This is not a WPF specific problem. (From:Windows Presentation Foundation (WPF))
    Saturday, April 10, 2010 11:49 PM

Answers

  • It was a directory/file permissions problem, although no error was ever surfaced from log4net, even when I tried

    log4net.Util.

    LogLog.InternalDebugging = true;

     

    • Marked as answer by WindowsRich Saturday, April 24, 2010 7:55 PM
    Sunday, April 11, 2010 6:34 PM

All replies

  • Issue still remains, even though I tried this different approach (no app.config stuff). No errors are thrown when the C# executes, but no log.txt file is written. Any ideas?

    public partial class Publisher : UserControl

        {

            // protected static readonly ILog log = LogManager.GetLogger(typeof(Publisher));

            protected static readonly ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

     

     

    in constructor call -

    log4net.Layout.PatternLayout pl = new log4net.Layout.PatternLayout( "%utcdate{dd MMM yyyy HH:mm:ss,fff} [%thread] %-5level %logger - %message%newline" );

    pl.ActivateOptions();

     

    RollingFileAppender rfa = new RollingFileAppender();

    rfa.File = "log.txt";

    rfa.AppendToFile = true;

    rfa.ImmediateFlush = true;

    rfa.DatePattern = "yyyyMMdd-HHmm";

    rfa.RollingStyle = RollingFileAppender.RollingMode.Date;

    rfa.Name = "PublisherRollingFileAppender";

    rfa.Layout = pl;

    rfa.ActivateOptions();

     

    BasicConfigurator.Configure(rfa);

     

    log.Debug("log4net test message, Debug level.");

    log.Info("log4net test message, Info level.");

    log.Warn("log4net test message, Warn level.");

    log.Error("log4net test message, Error level.");

    log.Fatal("log4net test message, Fatal level.");

     

     

     

    Sunday, April 11, 2010 5:42 PM
  • It was a directory/file permissions problem, although no error was ever surfaced from log4net, even when I tried

    log4net.Util.

    LogLog.InternalDebugging = true;

     

    • Marked as answer by WindowsRich Saturday, April 24, 2010 7:55 PM
    Sunday, April 11, 2010 6:34 PM