Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET Tracing: What is the "Default" listener?

Tags:

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?

like image 436
Ian Boyd Avatar asked Nov 04 '11 13:11

Ian Boyd


People also ask

What is the predefined trace listener in asp net?

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.

What are listeners in C#?

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.


1 Answers

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.

like image 117
Jon Skeet Avatar answered Oct 04 '22 17:10

Jon Skeet