How should I configure log4net to write to %LOCALAPPDATA% on Windows XP and 7?

If this isn't working, it would imply your environment variable is wrong.

Log4net does not have anything special in it to handle either appdata or localappdata. All it does is call System.Environment.GetEnvironmentVariables() to return a hashtable and performs substitution based on whatever values that returns.


VERY late to the party here but I just came across this and the found the answer.

Seems you can use log4net.Util.PatternString to insert environment variables into the file path. So the OP's example becomes:

<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
  <file type="log4net.Util.PatternString" value="%env{LOCALAPPDATA}\Vendor\App\application.log" />
  <appendToFile value="true" />
  <rollingStyle value="Size" />
  <maxSizeRollBackups value="10" />
  <maximumFileSize value="100KB" />
  <staticLogFileName value="true" />
  <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%date [%thread] %-5level %logger%newline%message%newline" />
  </layout>
</appender>

Add type="log4net.Util.PatternString" to the file element and then specify the %env pattern specifier followed by the environment variable name in curly brackets.