8

I have some code that will be logging using the Logging Application Block in Enterprise Library 5.0 from different threads. Is the LAB thread safe? Can I log like normal from different threads or will I need to synchronize the logging code so that is only used from one thread at a time?

Randy Levy
  • 22,566
  • 4
  • 68
  • 94
John Mills
  • 10,020
  • 12
  • 74
  • 121

2 Answers2

9

Enterprise Library 5.0 logging is thread safe.

Before logging, EL checks the IsThreadSafe property of the TraceListener. If the specific TraceListener is not thread safe then it will perform a Monitor.Enter(listener); before calling the listener's TraceData method.

Randy Levy
  • 22,566
  • 4
  • 68
  • 94
  • i'm wondering if I should have been able to figure this out or if going to the source is what's required to find out – Aaron Anodide Apr 10 '12 at 16:46
  • 1
    @Gabriel, I don't see any discussion of logging thread safety in the official docs only discussion about the Caching Block. I did see a third party site saying it is thread safe but better to verify. – Randy Levy Apr 11 '12 at 01:56
0

As far as I know,Enterprise Library 3.1 Logging is not thread safe. There is not lock around GetAvailableTraceListeners(IList traceListeners) call in LogWriter class, which used static in Logger class.

xuhy
  • 1