Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How are TraceSource names resolved in a .NET program?

The MSDN documentation for the TraceSource class has an example of how the app.config file can list out information for TraceSource instances:

http://msdn.microsoft.com/en-us/library/system.diagnostics.tracesource.aspx

However, there is no information on where the TraceSource values are stored...where are the existing TraceSource objects stored? When are they (edit: they means configured instances) constructed? How does the TraceSource object know how to return a named instance (edit: should be configured instance) instead of a new instance when creating a TraceSource object? Can I find a list of existing TraceSource objects without using Reflection?

like image 310
Matt Avatar asked Dec 13 '12 21:12

Matt


1 Answers

The TraceSource class keeps a private List of sources. But that isn't accessible by anyone but the TraceSource class itself.

The .config file section is meant to configure the listeners for a trace source. So when you create a TraceSource in your code, it uses the name you passed in the constructor and goes looking in the .config file to see what listeners should be added or removed automatically.

So code creates the a source, the .config file configures it. Not the other way around, a .config file cannot create a source.

like image 137
Hans Passant Avatar answered Oct 16 '22 13:10

Hans Passant