Mark
Mark

Reputation: 983

How do I create a new file for each log4net logger instance?

I am trying to create a different log file for each thread (the threads are handling some site processing). Essentially just naming the log file with a name that is derived from the site that is being processed.

I know all about the GlobalContext.properties and also the TheadContext.properties and neither really seem to work for what I am trying to do. In pretty much either case any concurrently running threads just use whichever file is the current output file as their output. The only difference I have seen is that if I use the ThreadContext to set the property it makes all the files but only outputs to one, where using global it seems to only make the one file unless the processes start at different times.

What I would REALLY like to do is be able to tell the file to just use the name of the logger object (the name that is used in instantiating the object) in the file name instead of using these properties.

Upvotes: 0

Views: 634

Answers (1)

Anthony Mastrean
Anthony Mastrean

Reputation: 22384

Instead of fighting the configuration, I recommend that you rethink your logging strategy. log4net was not built for a log file per thread/class. Loggers are created at startup or on first write (depends). Use a tailing log file reader, like Kiwi Log Viewer or Splunk, and filter on the thread id or logger name in your messages.

If you put them in your conversion pattern...

<conversionPattern value="%date [%thread] %-5level %logger: %message%newline" />

Upvotes: 1

Related Questions