Reputation: 3
I am trying to use log4net to track possible errors in my project.
I am using a WCF service, a client and a server lib.
The issue I am having is that whenever I run the project, and I want to test this, It will create the log files in the correct directory but It never write on it, not even if I put Logger.Info("test"); in the first call.
I have check a lot a sites and I have try a lot of things and nothing seems to work.
log4net.onfig:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
</configSections>
<log4net>
<root>
<level value="ALL" />
<appender-ref ref="GeneralAppender" />
</root>
<logger name="GeneralLogger">
<level value="ALL" />
<appender-ref ref="GeneralAppender" />
</logger>
<appender name="GeneralAppender" type="log4net.Appender.RollingFileAppender">
<file value="C:\Users\myUser\Desktop\mylog.log" />
<appendToFile value="true" />
<rollingStyle value="SIze" />
<datePattern value="yyyy/MM/dd HH:mm:ss.ff" />
<maxSizeRollBackups value="10" />
<maximumFileSize value="10MB" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] - [%logger] %message%newline" />
</layout>
</appender>
</log4net>
</configuration>
this file is locate in the service project and in the library both files have set the "Copy to Output Directory" property to "Copy if newer"
I have modifify the AssemblyInfo.cs
[assembly: log4net.Config.XmlConfigurator(ConfigFile = "log4net.config", Watch = true)]
The way to decalre the variable is:
static readonly log4net.ILog _Logger = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
The way in which I use the logger is the following:
_Logger.Info("some info");
_Logger.Error("This is an error", Exception);
Upvotes: 0
Views: 1494
Reputation: 4094
I've had this issue before; try adding the following line of code to your service startup.
XmlConfigurator.Configure();
It's part of the log4net.Config namespace.
Upvotes: 2