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?

4

1 回答 1

0

APPDATA 要求已创建用户配置文件。网络服务帐户不会出现这种情况。如果您以显式身份运行应用程序池,我相信此身份至少需要登录一次才能创建配置文件。

我建议您不要依赖 Web 应用程序中存在的用户配置文件,并为您的日志文件选择其他位置。

于 2011-09-07T09:11:19.963 回答