Like many others, I'm trying to implement Log4net into my C#.net application and I just can't get it to work for me. I've done a lot of searching (including on this site) and have tried many different solutions but nothing has worked for me yet. So the simple question: What am I doing wrong???
Assembly.cs contains the following line.
[assembly: log4net.Config.XmlConfigurator(Watch = true)]
App.config contains the following.
<configSections>
<section name="log4net"
type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
</configSections>
<log4net>
<root>
<level value="ALL"/>
<appender-ref value="RollingFileAppender"/>
<appender-ref value="ConsoleAppender"/>
</root>
<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
<param name="File" value="C:\Temp\Minion.log" />
<appendToFile value="true" />
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="5" />
<maximumFileSize value="10MB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date{Y-m-d H:i:s.u} | %thread | %method | %level | %message%newline" />
</layout>
</appender>
<appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender" >
<layout type="log4net.Layout.PatternLayout">
<param name="Header" value="[Header]\r\n" />
<param name="Footer" value="[Footer]\r\n" />
<param name="ConversionPattern" value="%date{Y-m-d H:i:s.u} | %thread | %method | %level | %message%newline" />
</layout>
</appender>
</log4net>
My code contains the following at the start of the class.
private static readonly ILog logger =
LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
And these tests at the start of the main function.
logger.Debug("test1");
logger.Info("test2");
logger.Warn("test3");
logger.Error("test4");
logger.Fatal("test5");
EDIT:
A tip led to the following errors during log4net initializaiton.
log4net:ERROR XmlHierarchyConfigurator: No appender named [] could be found.
log4net:ERROR Appender named [] not found.
log4net:ERROR XmlHierarchyConfigurator: No appender named [] could be found.
log4net:ERROR Appender named [] not found.
Change this:
<appender-ref value="RollingFileAppender"/>
<appender-ref value="ConsoleAppender"/>
to this:
<appender-ref ref="RollingFileAppender"/>
<appender-ref ref="ConsoleAppender"/>
And see if it won't cooperate better.
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