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 Mon, 06 Oct 2008 03:48:21 GMT
The source code to log4net is available at:

 http://svn.apache.org/viewvc/logging/log4net/trunk/src/

If you're wondering how something works that may be a better place to look. Most (all?) of
the source is commented. 

Its acceptable to create a new repository for medium to long running tasks. When you shutdown
the repository it automatically shuts down all of its appenders and loggers.



----- Original Message ----
From: Mark A. DeMichele <demi@intellipro.com>
To: Log4NET User <log4net-user@logging.apache.org>
Sent: Sunday, October 5, 2008 6:19:07 PM
Subject: RE: Using log4Net to log multiple files by different users/tasks

 
I'm not sure you're completing understanding my 
dilema.  I need to basically create loggers on the fly which are associated 
with separate files.
 
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 users/tasks


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:

http://svn.apache.org/viewvc/logging/log4net/trunk/examples/net/1.0/Appenders/SampleAppendersApp/cs/src/Appender/PatternFileAppender.cs?view=markup

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 
this.
 
PatternLayoutlayout = newPatternLayout("%date{dd-MM-yyyy HH:mm:ss,fff} %5level [%2thread]
%message 
(%logger{1}:%line)%n");
FileAppenderappender = newFileAppender();
appender.Layout = 
layout;
appender.File = "d:\\logs\\"+ TaskID.ToString()+ ".txt";
appender.AppendToFile = true;
appender.Name = "File";
appender.Threshold = log4net.Core.Level.All;
appender.ActivateOptions();
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.
Thanks.
Mime
View raw message