0

I have a .NET web application that should log stuff to the APPDATA environment variable with log4net. On my XP dev computer it works just fine, but when deployed to a Windows 2003 server the logs are written to C:\ instead. I've tried using both Network Service and my own user account (with admin rights) for running the IIS app pool and there's no difference.

The log4net appender config looks like this:

<appender name="RollingFile" type="log4net.Appender.RollingFileAppender">
  <file value="${APPDATA}\appname\log."/>
  <appendToFile value="true" />
  <rollingStyle value="Date" />
  <staticLogFileName value="false" />
  <datePattern value="'.'yyyy-MM-dd'.txt'" />
  <maxSizeRollBackups value="14" />
  <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%date&#9;%-5level&#9;%message%newline" />
  </layout>
</appender>

I don't think there's a problem with write permissions, because it works if I change the config to this:

<file value="c:\Documents and Settings\username\Application Data\appname\log."/>

Anyone has any idea what's wrong and how to fix it?

Tetaxa
  • 4,375
  • 1
  • 19
  • 25

1 Answers1

0

The APPDATA requires a user profile to have been created. This won't be the case for the Network Service account. If you run the Application Pool under an explicit identity, I believe this identity will need to have logged in at least once to create the profile.

I suggest you don't rely on the existence of a user profile in web applications, and choose some other location for your log files.

Joe
  • 122,218
  • 32
  • 205
  • 338
  • That explains the Network Service then, but my own account has been logged in plenty and still no luck. – Tetaxa Sep 07 '11 at 09:15
  • Could it be this, but also that the web application runs as ASPNET and NOT as the user of the application pool, and the ASPNET user has no profile? – Tetaxa Sep 07 '11 at 12:21
  • Have you configured the APp pool to load the user profile? http://blogs.msdn.com/b/vijaysk/archive/2009/03/08/iis-7-tip-3-you-can-now-load-the-user-profile-of-the-application-pool-identity.aspx – Joe Sep 07 '11 at 15:27
  • It's on IIS6, so I can't. Seems I have to abandon the whole appdata-approach like you first suggested. Thanks! – Tetaxa Sep 08 '11 at 13:20