log4net creates log file but does not write to it (windows service in C#)
Posted
by
user1825172
on Stack Overflow
See other posts from Stack Overflow
or by user1825172
Published on 2012-11-14T22:39:49Z
Indexed on
2012/11/14
23:00 UTC
Read the original article
Hit count: 377
I am trying to use basic logging for a windows service.
I added the reference to log4net
I added the following in AssemblyInfo.cs:
[assembly: log4net.Config.XmlConfigurator(Watch = true)]
I added the following to my App.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821" requirePermission="false" />
</configSections>
<!-- Log4net Logging Setup -->
<log4net>
<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender,log4net">
<file value="c:\\CGSD\\log\\logfile.txt" />
<appendToFile value="true" />
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %level %logger - %message%newline" />
</layout>
<filter type="log4net.Filter.LevelRangeFilter">
<levelMin value="INFO" />
<levelMax value="FATAL" />
</filter>
</appender>
<root>
<level value="ALL"/>
<appender-ref ref="RollingFileAppender"/>
</root>
</log4net>
</configuration>
I have the following code in my service:
log4net.Config.XmlConfigurator.Configure();
log4net.ILog log = log4net.LogManager.GetLogger(typeof(Program));
log.Debug("test");
the file c:\CGSD\log\logfile.txt is created but nothing is ever written to it.
i've been thru the forums all day trying to trac this one down, but if i overlooked an already posted solution i apologize.
thx!
© Stack Overflow or respective owner