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	%-5level	%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?
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.