jeroenvdbergh
jeroenvdbergh

Reputation: 362

Log4net doesn't create a log file on a production server

I know there are already a lot of log4net questions asked on Stack Overflow but they can't seem to fix my specific problem.

The log4net configuration below is used for my application.

<log4net>
  <appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
    <file value="E:\Logs\" />
    <datePattern value="yyyy-MM-dd'_APP.log'" />
    <appendToFile value="true" />
    <immediateFlush value="true" />
    <rollingStyle value="DATE" />
    <staticLogFileName value="false" />
    <maxSizeRollBackups value="10" />
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%date||%2thread||%-5level||%logger||%message%newline" />
    </layout>
  </appender>
</log4net>

I left out some parts that are not interesting. Using this configuration the application is not logging on the production server. On my local development PC it is working fine. When I enable log4net debugging mode I see it can't access the "E:\Logs\" directory because the access is denied.

I added all of the needed permissions to this folder already. Now here comes the part I don't get. After some debugging I found out that appending something after the \ in the tag, it suddenly works. So the configuration below works fine.

<log4net>
  <appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
    <file value="E:\Logs\x" />
    <datePattern value="yyyy-MM-dd'_APP.log'" />
    <appendToFile value="true" />
    <immediateFlush value="true" />
    <rollingStyle value="DATE" />
    <staticLogFileName value="false" />
    <maxSizeRollBackups value="10" />
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%date||%2thread||%-5level||%logger||%message%newline" />
    </layout>
  </appender>
</log4net>

This creates a log file x2018-11-07_APP.log, but I don't want to append the x...

Can someone clarify for me why it behaves like this?

Thanks!

Upvotes: 1

Views: 880

Answers (1)

jeroenvdbergh
jeroenvdbergh

Reputation: 362

The answer provided by Fildor worked like a charm.

<file value="E:\Logs\.log" /> 
<datePattern value="yyyy-MM-dd'_APP'" /> 
<preserveLogFileNameExtension value="true"/>

It's still weird that it's working fine on the development PC.

Upvotes: 2

Related Questions