logging-log4net-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Francine Taylor" <Francine.Tay...@genesis-fs.com>
Subject RE: Using log4Net to log multiple files by different users/tasks
Date Mon, 06 Oct 2008 20:00:04 GMT
What about a system where you have a "bank" of loggers?


First, you could have an array which would contain three values; the
generated logger name, a flag indicating whether the logger was being
used, and a task ID (empty if the logger was not being used).


Whenever you need a new logger, you check to see if one is available.
If not, you create it and add an entry to the logger array.


Either way, you just call the RemoveAllAppenders() method on that
logger, create an appender and attach it to the logger, set the task ID
for the logger, and mark it as not available.



From: Mark A. DeMichele [mailto:demi@intellipro.com] 
Sent: Sunday, October 05, 2008 3:19 PM
To: Log4NET User
Subject: RE: Using log4Net to log multiple files by different


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.


NOTICE: The contents of this e-mail message and any attachments are intended solely for the
addressee(s) named in this message. This communication is intended to be and to remain confidential.
If you are not the intended recipient of this message, or if this message has been addressed
to you in error, please immediately alert the sender by reply e-mail and then delete this
message and its attachments. Do not deliver, distribute or copy this message and/or any attachments
and if you are not the intended recipient, do not disclose the contents or take any action
in reliance upon the information contained in this communication or any attachments.
Thank you

View raw message