logging-log4net-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mark A. DeMichele" <d...@intellipro.com>
Subject RE: Using log4Net to log multiple files by different users/tasks
Date Sun, 05 Oct 2008 22:19:07 GMT
I'm not sure you're completing understanding my dilema.  I need to
basically create loggers on the fly which are associated with separate
I did actually get something working, but now I can't figure out how to
clean up.  This is what I have so far. 
To start I create a repostitory and give it a name.  I then store the
repository pointer in a static variable.
Then when I start a specific task, I use the repository to create a
logger and I add a file appender to that logger.  The file appender is
associtated with a unique file name.  My task has a unique id and I used
tha same id to name the logger.  All my logging for that task uses that
logger with that name and everything seems ok.
Now here's the problem.  When my task is done, I would like to clean up
that logger and remove it from the repositry, but there doesn't seem to
be a way to do this.  I fear that based on my design, if my server is
running for days on end, the hash table where the loggers are stored in
the repository will grow and grow.   I used Reflector to look at the
code in the Hierarchy object. but there doesn't seem to be a way to
remove an object from the hash table.


From: Ron Grabowski [mailto:rongrabowski@yahoo.com] 
Sent: Sunday, October 05, 2008 11:51 AM
To: Log4NET User
Subject: Re: Using log4Net to log multiple files by different

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
So far, I believe I must create an individual Appender for each task.
Something like this.
PatternLayout layout = new PatternLayout("%date{dd-MM-yyyy HH:mm:ss,fff}
%5level [%2thread] %message (%logger{1}:%line)%n");
FileAppender appender = new FileAppender();
appender.Layout = 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 tasks.

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