How to force logging trace listeners to be singleton

Topics: Exception Handling Application Block, Logging Application Block
Aug 7, 2013 at 10:52 AM
Hi,

I have a typical logging + exception handling configuration in entlib 5.
The logging configuration declares a named trace listener to be used in every logging activity.
The exception handling configuration instructs entlib to log exceptions using the category that is associated to that single trace listener.

My surprise is that the trace listener is instantiated twice. My guess is that it is instantiated first as part of the logging configuration and then as part of the exception handling logic.

Is there a way to prevent this?
The problem is that my listener is a custom trace listener that assumes it is the only writer to the log file, and uses a custom mechanism to serialize writes; with two instances writing simultaneously, lines from each one get intermingled.
I expected one instance per named trace listener to be created, even if it is used both by the logger and by the exception manager.

Thank you very much.
Aug 7, 2013 at 11:03 PM
Edited Aug 7, 2013 at 11:03 PM
I don't see two trace listeners being instantiated in my testing. Perhaps you can give a specific scenario?

Also, the Logging Application Block is thread-safe so your custom trace listener shouldn't have to implement it's own syncrhonization code. If you override the IsThreadSafe property and set it to false then Enterprise Library will manage synchronizing access to your trace listener.

~~
Randy Levy
entlib.support@live.com
Enterprise Library support engineer
Support How-to