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?
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.
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 thread-safe? Yes, log4net is thread-safe.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With