Reputation: 13
I have a program that is spawning multiple threads dynamically. I'd like to introduce logging so that each thread can log to its own log file.
Using Enterprise Library 4.1, is it possible for each thread (created dynamically at runtime) to log to a unique log file associated with that thread?
For example
Thread 1 -> mylog1.log Thread 2 -> mylog2.log ... Thread N -> mylogN.log
I've read the following threads which have shed light but failed to provide a viable solution.
Write to multiple files Enterprise Library Logger
Entreprise Library Rolling flat file is not rolling
Implementing Log file using Enterprise Library in asp.net
Microsoft Logging application block and multi-threading
Should I be looking at another framework that is capable of this? Log4net?
Thanks
Upvotes: 1
Views: 2709
Reputation: 22655
The approach you are describing is not a natural fit with the configuration based approach of Enterprise Library where each Trace Listener maps to one file and is set at design time.
However you should be able to achieve what you want using a programmatic approach. For each thread you could programmatically create a LogWriter and then use this LogWriter for all logging for that thread.
Some of the older articles on programmatic logging should still apply for version 4. For example: Programatic Configuraton - Enterprise Library (v2.0) Logging Block. Note that there are changes in version 5 (LogWriter is now abstract for example) that could break the older implementations.
Upvotes: 2