Logging to flat file Thread-safe?

Topics: Logging Application Block
Apr 30, 2011 at 1:30 PM

Hi,

I was wondering if logging with a Flat File Trace Listener is thread-safe?

I will be running a multi-threading app and want to log to a single file, but anyone knows if this will give problems if 2 threads will be logging at the same time?

Thank you.

May 2, 2011 at 3:35 AM

Hi,

Looking at the source code, I can say that it is thread safe. This is not only specific to Flat File but with other trace listeners as well. Prior to logging, it checks the IsThreadSafe property of the TraceListener. If that is not thread safe, then it will perform a Monitor.Enter(listener) before calling the listener's TraceData method.

 

Noel Angelo Bolasoc
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com

May 2, 2011 at 8:23 AM

Great news.

Thanks.