问题
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?
回答1:
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.
回答2:
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.
来源:https://stackoverflow.com/questions/2926466/is-the-microsoft-enterprise-library-5-0-logging-application-block-thread-safe