Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom filename in a rolling Log4Net logfile?

We have a ASP .Net application whereby we use Log4Net to log details within the app - nothing new there - and the rolling log filenames are in the usual format of:

rolling-log.txt 
rolling-log.txt.1
rolling-log.txt.2 etc.

A each user of the application adds to the logfile, the logfile can be difficult to read for a specific user's case and so, we'd like to modify the config file somehow to record the user's log details individually, each writing to a specific file, e.g.

<applicationId>rolling-log.txt
<applicationId>rolling-log.txt.1
<applicationId>rolling-log.txt.2
etc.

where is each user's unique application Id, made up of a five digit number, e.g.

12345rolling-log.txt

Any ideas on the best way to implement this, assuming that it's possible?

Cheers

Brett

like image 325
Brett Rigby Avatar asked Jun 23 '09 07:06

Brett Rigby


People also ask

What is rolling file Appender 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.

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.


2 Answers

<file type="log4net.Util.PatternString">
  <conversionPattern value="C:\Logs\log-%date{ yyyy.MM.dd.HH.mm.ss}-[%processid].log" />
</file>

from here

like image 142
isobretatel Avatar answered Sep 20 '22 13:09

isobretatel


look for log4net Context Properties...

in your code :

log4net.GlobalContext.Properties["id"] = "12345";

then

log4net.Config.XmlConfigurator.ConfigureAndWatch(new FileInfo("configPath"));

in the log4net config file:

<file type="log4net.Util.PatternString"
            value="%property{id}rolling-log.txt" />
like image 42
Butu Avatar answered Sep 23 '22 13:09

Butu