If you want to define appenders at runtime you can do this through the
log4net API. You will need to attach each appender to a separate logger
in the hierarchy and configure each thread to log to its logger. If you
have a large number of threads then you will also end up with a
corresponding number of appenders, which you will need to cleanup,
log4net by default will wait until the application is shutdown before
closing all the appenders. 

A better solution is to use the same loggers for all the threads, but to
identify the source thread using the ThreadContext.Properties. This is a
thread local storage area that is attached to each LoggingEvent object
generated internally in log4net. Then it is up to the appender how and
where it decides to log the message depending on the data in the
LoggingEvent.

For an example of how to set up something like this see:
http://marc.theaimsgroup.com/?l=log4net-user&m=111885501730466&w=2

Cheers,

Nicko

> -----Original Message-----
> From: Sharon Gur [mailto:[EMAIL PROTECTED] 
> Sent: 16 June 2005 20:01
> To: [email protected]
> Subject: Different threads writing to different log files
> 
> Hi,
>  
> I want to have different (and multiple) threads write to 
> different log files. The number of threads varies (I don't 
> know how many threads will run). 
> I thought the best way to do this will be by adding loggers 
> and appenders programmatically. Is it possible? Is there 
> another way to implement this?
>  
> Thank you,
> Sharon
> 

Reply via email to