Multiple threads each writing to their own log file

116 views
Skip to first unread message

Rick Langel

unread,
Nov 13, 2013, 6:39:21 PM11/13/13
to nlog-...@googlegroups.com
 
I've got a process which starts up multiple threads each of which do work continually during the day.  I want each thread to write to it's own log file with the following as the file name format.  It doesn't seem to work quite right.
 
fileName="${basedir}/logs/${mdc:item=task}_${shortdate}.log"
 
I've tried using MappedDiagnosticsContext.Set to set a thread specific item name for the logger to use, but that only works the first time the log is written to for that thread, the next thread changes the item name and everything is written to whatever the last name was. 
 
Is there a way to configure multiple threads to each write to their own log file?
 
Rick
 
 

kimwo...@gmail.com

unread,
Nov 14, 2013, 5:07:13 PM11/14/13
to nlog-...@googlegroups.com
The easiest way to do this would probably to to create a specific target for each thread, as the filename is cached per target

Rick Langel

unread,
Nov 14, 2013, 5:54:00 PM11/14/13
to nlog-...@googlegroups.com

I've tried that, but whatever thread last got their reference to the logger is where all log events go to.

Kim Christensen

unread,
Nov 14, 2013, 6:40:40 PM11/14/13
to nlog-...@googlegroups.com

You also need to have multiple loggers, but it can be cumbersome to do for each thread. Feel free to create a feature request at github.

Reply all
Reply to author
Forward
0 new messages