Log4net log is created but remains blank

I am trying to use log4net . When I launch the application, it creates a log file, but no matter how many times I call Log.Info("Application Started"); It stays empty. I examined the first two pages that google returns, and my code seems to follow all the examples.

the 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 guidance on what might be wrong?

+8
c # winforms log4net
source share
1 answer

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

It turns out that the <configSections></configSections> were not directly children of the <configuration> , which means that the configuration will not be selected (I assume), and since log4net swallows all the exceptions, this only showed up in my application.

Now the registration is working fine.

+6
source share

All Articles