Every example of tracing in .NET people remove the "Default
" listener:
<configuration> <system.diagnostics> <sources> <source name="TraceSourceApp" switchName="SourceSwitch" switchType="System.Diagnostics.SourceSwitch"> <listeners> <add name="ConsoleListener"/> <add name="ETWListener"/> <remove name="Default"/> </listeners>
What is the Default listener, and why is it there by default?
A Microsoft guy did benchmarks of the overhead with different listeners:
Default |===============================14,196 ms=====/ /================> TextWriterTraceListener |=========211 ms======> EventProviderTraceListener |=> 77ms
What is the Default
trace listener, and why is it so slow? Is it OutputDebugString
? Is OutputDebugString
really two orders of magnitude slower than writing to a file?
Is there a .NET TraceListener
that just uses OutputDebugString
?
What is the default trace listener, why is it so slow, why is it customarily removed, and if it's so bad why is it the default?
The following are the commonly used predefined listeners: A TextWriterTraceListener redirects output to an instance of the TextWriter class or to anything that is a Stream class. It can also write to the console or to a file, because these are Stream classes. An EventLogTraceListener redirects output to an event log.
An event listener represents the target for all events generated by event source (EventSource object) implementations in the current application domain. When a new event listener is created, it is logically attached to all event sources in that application domain. This type implements the IDisposable interface.
It's not clear from that blog post how the code was run, but the DefaultTraceListener
is documented like this:
By default, the Write and WriteLine methods emit the message to the Win32 OutputDebugString function and to the Debugger.Log method. For information about the OutputDebugString function, see the Platform SDK or MSDN.
So if Debugger.Log
is actually printing to a UI window (and quite possibly scrolling it etc) I can see that causing a lot of the slowdown.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With