I can't believe i'm having to ask this but here goes ...
I'm trying to setup log4net in a new WPF app and for some reason it's not creating the log file and logging anything, so here's the steps I've done so far ...
After adding the latest version (v2.0.8.0) reference from nuget.
In AssemblyInfo.cs:
[assembly: log4net.Config.XmlConfigurator(ConfigFile = "Log4Net.config", Watch = true)]
In app.config:
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net, Version=2.0.8.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a" />
</configSections>
<log4net configSource="Log4Net.config" />
In Log4Net.config:
<?xml version="1.0" encoding="utf-8"?>
<log4net>
<appender name="rollingLogFile" type="log4net.Appender.RollingFileAppender">
<file value="D:\Logs\WorkflowApp.log" />
<appendToFile value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="10" />
<maximumFileSize value="100KB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-6level %logger - %message %exception%newline" />
</layout>
</appender>
<root>
<level value="DEBUG" />
<appender-ref ref="rollingLogFile" />
</root>
</log4net>
In App.xaml.cs:
ILog log = LogManager.GetLogger(typeof(App));
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
log.Debug("Initialising ...");
}
As one last final "try it and see if it works" I added this to the above method ...
XmlConfigurator.Configure();
... still no long file created.
So what did I miss?
EDIT:
So based on comments, I thought I should add this:
I have seen questions & answers like this ... Using log4net to write to different loggers
... If I add something like this to my Log4Net.config ...
<logger name="File">
<level value="DEBUG" />
<appender-ref ref="rollingLogFile" />
</logger>
Then change my logger construction to ...
ILog log = LogManager.GetLogger("File");
... this however still results in nothing happening, no log file but no exceptions and the code appears to run fine other than the logging calls which appear to execute but with no results.
if you are in DEV, you need to copy the Log4Net.config into bin\debug ; done or not ? have to set copy to in propterties, or as resource file to be included in setup installer later. see you; thanks for your vote.
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