logging-log4net-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ron Grabowski <rongrabow...@yahoo.com>
Subject Re: Using log4Net to log multiple files by different users/tasks
Date Sun, 05 Oct 2008 15:51:28 GMT
In your code the File property gets set when the Appender is created. Here's an example showing
how to set the File property based on each logging event:


That example code is probably slow. log4j and nlog have file appenders that keep the most
recent files open so you don't have to pay the open/close penalty.

You could probably extend the FileAppender and override a method or two to do what you want.

----- Original Message ----
From: Mark A. DeMichele <demi@intellipro.com>
To: log4net-user@logging.apache.org
Sent: Sunday, October 5, 2008 9:43:05 AM
Subject: Using log4Net to log multiple files by different users/tasks

I have an asp.net 
site in which different users run different tasks.  Each individual task is 
managed by a TaskManager that I'm writing.  While each task is running it 
has the opportunity to log to it's own log file.  I'm trying to use Log4Net 
to do this, but so far I've been unable to figure out how exactly to accomplish 
this.  Any advice would be appreciated.
So far, I believe I 
must create an individual Appender for each task.  Something like 
PatternLayoutlayout = newPatternLayout("%date{dd-MM-yyyy HH:mm:ss,fff} %5level [%2thread]
FileAppenderappender = newFileAppender();
appender.Layout = 
appender.File = "d:\\logs\\"+ TaskID.ToString()+ ".txt";
appender.AppendToFile = true;
appender.Name = "File";
appender.Threshold = log4net.Core.Level.All;
And I know that 
eventaully, I'll want to code to call something like 
ILog _Log = LogManager.GetLogger(TaskID.ToString());
But I can't figure out 
how to make that logger unique and how to associate that single appender to it 
and not to have that single appender interfere with other users and 
I'm starting to think 
that this is not possible with Log4Net.  Maybe Log4Net is made more to have 
global loggers and not many individual task related ones.  I'd appreciate 
any help anyone can give me.
View raw message