Groups | Blog | Home
all groups > dotnet performance > february 2007 >

dotnet performance : System.Diagnostics.Trace.WriteLine


Ollie Riches
2/22/2007 12:00:00 AM
Just wonder what the cost of using the API
System.Diagnostics.Trace.WriteLine() is?

Infact does anyone know how this works internally - are all calls to the API
processed asynchronously by another thread and does it use some form of a
queue internally.

I guess this uses the win32 api 'OutputDebugString' is this true?

Cheers

Ollie Riches

Henning Krause [MVP - Exchange]
2/22/2007 11:13:45 PM
Hello,

[quoted text, click to view]

actually, it's more complicated.

The Trace class uses TraceListeners to which it delegates the messages. By
default, the DefaultTraceListener is added, which writes to the Win32
OutputDebugString function.

But you can add other (Like textfiles via TextWriterTraceListener) or create
eventlog entries (EventLogTraceListener).

I personally use the TraceSources nowadays, because you can use them as
"categories" which can be enabled and disabled via app.config and you can
have more than one in your application.

When I write console applications, I don't use Console.Out anymore, but add
a TextWriterTraceListener(Console.Out) to the Listener collection...

Now, the costs depend on the number of listeners you have and the verbosity
configured via the app.config file. You'll really have to measure it...

Best regards,
Henning Krause
AddThis Social Bookmark Button