Reputation: 141
I have a windows service project with log4net. If I install the service via installutil.exe then everything works fine. I adding windows setup project - service starting and work, but not creating log files.
My conf
<configSections>
<section name="ConnectionInfo" type="Astra.Common.Configuration.ConnectionInfoConfiguration, Astra.Common" />
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net, Version=2.0.8, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a" />
</configSections>
...
<log4net>
<appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender">
<param name="File" value="Logs\service.log" />
<param name="AppendToFile" value="true" />
<maxSizeRollBackups value="10" />
<maximumFileSize value="5MB" />
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%d %-5p %m%n" />
</layout>
</appender>
<logger name="LOGGER">
<appender-ref ref="LogFileAppender" />
</logger>
</log4net>
Class
public static class Logger
{
private static ILog log = LogManager.GetLogger("LOGGER");
public static ILog Log
{
get { return log; }
}
public static void InitLogger()
{
XmlConfigurator.Configure();
}
static Logger()
{
InitLogger();
}
}
[assembly: log4net.Config.XmlConfigurator(Watch = true)]
Service as NetworkService
Upvotes: 1
Views: 1977
Reputation: 27944
If you have a file appender, make sure you are writing to a location where the user is allowed to create and update the files. If not the logging will fail. You can check this when you have internal debugging enabled.
Upvotes: 2