What trace source is used by System.Diagnostics.Trace.WriteLine?

As far as I can see, there are two ways to create trace messages in .NET.

In my app.config file, I can either add a trace listener for everything:

 <system.diagnostics> <trace> <listeners> ... </listeners> </trace> </system.diagnostics> 

or for one specific trace source:

 <system.diagnostics> <sources> <source name="..."> <listeners> ... </listeners> </source> </sources> </system.diagnostics> 

My question

If I use the first method (static methods of System.Diagnostics.Trace), what trace source name is used?

I checked the MSDN System.Diagnostics.Trace page , but did not find the answer there.

+5
source share
1 answer

I checked the source of Trace.Writeline with JustDecompile and listed all the listeners and sent a message to everyone:

  foreach (TraceListener listener in TraceInternal.Listeners) { if (listener.IsThreadSafe) { listener.WriteLine(message); if (!TraceInternal.AutoFlush) { continue; } listener.Flush(); } else { lock (listener) { listener.WriteLine(message); if (TraceInternal.AutoFlush) { listener.Flush(); } } } } 

But forget about this ugly call to Trace, use ETW Eventsource for much better tracing / logging

+3
source

Source: https://habr.com/ru/post/1239341/


All Articles