DefaultTraceListener itself is "pretty fast" - as with the case, it is usually not noticeable with all but the most meaningless use. However, in combination with Trace.UseGlobalLock, it can have a significant impact on a heavily loaded system.
Today, our systems experienced excessive CPU utilization and context switching (which is another problem) .. and something unexpected happened that exacerbated the problem to such an extent that the work was effectively stopped:
The heavy threaded code began to block up to 12 seconds (!!) on Trace.WriteLine, since it had to acquire a lock on the โtrivialโ work in the DefaultTraceListener.
While UseGlobalLock is applied even if there is no trace listener, it is actually a lock with something inside - compared to a lock with a small tiny fragment of something inside that could snowball in an already loaded system with many threads.
The immediate fix is โโto disable UseGlobalLock (these are other side effects [disclaimer: another message]) and remove DefaultTraceListener.
Of course, if another trace listener is connected, it can very well obscure all the time spent in the DefaultTraceListener.
source share