I am using log4net to do my logging. I would like it to write to a file and to the eventlog at the same time.
For some reason, I find the messages twice in my logfile.
This is my app.config-section :
<log4net>
<root>
<level value="INFO" />
<appender-ref ref="LogFileAppender" />
<appender-ref ref="EventLogAppender" />
</root>
<appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender" >
<param name="File" value="c:\temp\DIS-logfile.txt" />
<param name="AppendToFile" value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="10" />
<maximumFileSize value="10MB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%date %-5level %logger - %message%newline" />
</layout>
</appender>
<appender name="EventLogAppender" type="log4net.Appender.EventLogAppender">
<param name="Indigo.DataIntakeService" value="eventlog" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date %-5level %logger - %message%newline" />
</layout>
</appender>
</log4net>
In my code I have tof following :
private static readonly ILog Log = log4net.LogManager.GetLogger("DataIntakeService");
private static readonly ILog LogEvents = log4net.LogManager.GetLogger("EventLogAppender");
static void Main(string[] args)
{
log4net.Config.XmlConfigurator.Configure();
}
public static void LogInfo(string message)
{
Log.Info(message);
LogEvents.Info(message);
}
It writes to my log-file, as requested, but the messages should also go to my eventviewer and that doesn't happen. It writes those messages to the logfile as well.
Where did I go wrong?