Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 612
m.edmondson Avatar asked Apr 24 '12 10:04

m.edmondson


People also ask

Where are log4net logs stored?

You can configure the log4net. config file to create log files. The file is located in the webroot\App_data directory of the installation. The different log files are described in Services logs.

What is rolling file Appender in log4net?

RollingFileAppender can roll log files based on size or date or both depending on the setting of the RollingStyle property. When set to Size the log file will be rolled once its size exceeds the MaximumFileSize.

Is log4net a Threadsafe?

Is log4net thread-safe? Yes, log4net is thread-safe.


1 Answers

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.

like image 172
m.edmondson Avatar answered Oct 14 '22 06:10

m.edmondson