Is the Microsoft Enterprise Library 5.0 Logging Ap

2019-02-21 21:34发布

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?

2条回答
我欲成王,谁敢阻挡
2楼-- · 2019-02-21 21:56

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.

查看更多
做个烂人
3楼-- · 2019-02-21 22:05

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.

查看更多
登录 后发表回答