views:

22

answers:

1

Logs in a Windows Service are not written to the path of the exe because the windows service is started in another directory. What's the best way to write the logs to the AppDomain.CurrentDomain.BaseDirectory?

This is my appender:

<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
  <!--<file value="Logs/Log4Net/"/>-->
  <appendToFile value="true"/>
  <rollingStyle value="Date"/>
  <staticLogFileName value="false"/>
  <lockingModel type="log4net.Appender.FileAppender+MinimalLock"/>
  <datePattern value="yyyy-MM-dd-HH.lo\g"/>
  <maximumFileSize value="1MB"/>
  <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%date %-5level %logger - %message%newline"/>
  </layout>
</appender>

I have found a way to set it dynamically in code, but no way to set it right in the xml configuration...

+2  A: 

Only elevated accounts can write in the installation directory.

You have to log in applictation data folder instead. Check this:

http://stackoverflow.com/questions/468989/how-to-specifiy-common-application-data-folder-for-log4net

Pierre 303