Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify common application data folder for log4net?

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?

like image 218
user57474 Avatar asked Jan 22 '09 12:01

user57474


People also ask

Where is log4net configuration file?

You can configure the log4net. config file to create log files. The file is located in the webroot\App_data directory of the installation.

What is RollingFileAppender in log4net?

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.

Does log4net create directory?

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.


2 Answers

We just use this:

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

It works great.


This line can simply be inserted into your current appender configuration:
<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">    <param name="File" value="${ALLUSERSPROFILE}/Company/Product/Logs/error.log"/> </appender> 
like image 74
pduncan Avatar answered Sep 20 '22 08:09

pduncan


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

like image 20
pilif Avatar answered Sep 21 '22 08:09

pilif