简体   繁体   中英

log4net log being created but remaining empty

I'm attempting to use log4net . When I fire up the app it creates the log file, but no matter how many times I call Log.Info("Application Started"); it remains empty. I've researched the first two pages that google returns and my code seems to match all examples.

Code:

[assembly: XmlConfigurator(Watch = true)]

namespace Generator
{
     public class Run
     {

       private static readonly log4net.ILog Log =
       log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

        public List<BILL_RUN> PerformBillRun()
        {
             XmlConfigurator.Configure();

             Log.Info("Application Started");
             var enabled = Log.IsInfoEnabled; //This is true
        }

     }

}

app.config

  <configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
  </configSections>

  <log4net>
    <appender name="FileAppender" type="log4net.Appender.FileAppender">
      <file value="log-files.txt" />
      <appendToFile value="true" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
      </layout>
    </appender>

    <root>
      <level value="All" />
      <appender-ref ref="FileAppender" />
    </root>
  </log4net>

Any pointers as to what may be wrong?

This always happens to me...as soon as I post the question.

It turns out my <configSections></configSections> tags weren't directly a child to <configuration> meaning that the config wouldn't be picked up (I assume), and because log4net swallows all exceptions this only manifested itself further into my app.

Logging is working fine now.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM