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?
You can configure the log4net. config file to create log files. The file is located in the webroot\App_data directory of the installation.
RollingFileAppender means the system creates a log file based on your filters, this way you can have log files based on dates (one file each day), or get the file splitted into small chunks when it hits certain size.
Log4net watches for any new file created in the folder so simply creating the . log4net configuration file triggers the update within the component that is logging. When using a file appender, the destination folder does not have to exist. Log4net creates the folder.
We just use this:
<param name="File" value="${ALLUSERSPROFILE}/Company/Product/Logs/error.log"/>
It works great.
<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender"> <param name="File" value="${ALLUSERSPROFILE}/Company/Product/Logs/error.log"/> </appender>
This posting on the log4net mailinglist explains how you can define your own path replacement variables.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With