Multi threading causing duplicate messages being logged

Topics: Logging Application Block
Feb 14, 2014 at 7:12 PM
Hello,

I am having an issue with Ent Lib logging (v5) where when i have an application that have multiple threads logging to the same Trace Listener, sometimes it will log the same message twice. I'm not sure if anyone else ever came accross this issue? Not sure if this could be related to the Trace Listeners not being thread safe?

Thanks,
Feb 16, 2014 at 6:13 AM
The logging block writes are thread-safe so it's hard to say what is happening. Writes are synchronous so there should be no issue with reading from a queue and locks are performed around writing when trace listeners that are not thread-safe (e.g. flat file trace listener) are involved.

Can you elaborate on the exact scenario? I know you say it's intermittent but perhaps a sample project that tries to replicate the issue would help.

~~
Randy Levy
entlib.support@live.com
Enterprise Library support engineer
Support How-to
Feb 18, 2014 at 2:30 PM
Hi Randy,

I will try and see if I can create a sample project that could recreate the scenario. I have two custom trace listeners, one to write to a file in xml format and another to generate IPC messages to retrieve from a UI. Once I have something, I will see if I can send it to you.

Thanks,
Shakib
Feb 18, 2014 at 2:48 PM
What does the custom xml file trace listener inherit from and does it override TraceListener.IsThreadSafe?

~~
Randy Levy
entlib.support@live.com
Enterprise Library support engineer
Support How-to
Feb 18, 2014 at 2:55 PM
Edited Feb 18, 2014 at 2:58 PM
My two TraceListeners inherit from "CustomeTraceListener" which inherits from "TraceListener" which resides in the Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners namespace. I tried overriding the TraceListener.IsThreadSafe and setting it to true as well as setting Trace.UseGlobalLock to false, but that didn't help too much.