views:

2402

answers:

2

I want log4net to write log files (using RollingFileAppender) to a subfolder of the common application data folder (e.g. C:\Documents and Settings\All Users\Application Data\Company\Product\Logs).
However, on Win XP, there is no environment variable that specifies this folder. We have %ALLUSERSPROFILE%, we have %APPDATA%, but there is nothing like %ALLUSERSAPPDATA%.
Programatically, I could use Environment.SpecialFolder.CommonApplicationData, but I need to put it in the log4net config, something like this:

<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
   <file value="%ALLUSERSAPPDATA%\Company\Product\Logs\error.log" />
</appender>

OK, we could define this in our setup, but maybe someone comes up with a better idea?

+3  A: 

This posting on the log4net mailinglist explains how you can define your own path replacement variables.

pilif
Thanks, this gave me the right idea. I will define a property and use a PatternString for the folder in the config file.
+2  A: 

We just use this:

<param name="File" value="${ALLUSERSPROFILE}/Company/Product/Logs/error.log"/>

It works great.

pduncan