Partilhar via


My Favorite System.Net trace configuration file dumps Process ID and Date Time Information

Often you need to correlate a .NET trace with a Netmon trace.  To do that you need the date and time of the call from the System.Net trace.  This will do it!

NOTE:  This section is configures where the log file is and where it should be written: initializeData="System.Net.trace.log"
Specify the path and file name and make sure the process running has permissions to write that file in the location you specify!

 

Copy Code:

<configuration>
    <system.diagnostics>
        <trace autoflush="true" />
                <sources>
                <source name="System.Net">
                        <listeners>
                <add name="System.Net"/>
                        </listeners>
                </source>
                <source name="System.Net.HttpListener">
                        <listeners>
                <add name="System.Net"/>
                        </listeners>
                </source>
        <source name="System.Net.Sockets">
                        <listeners>
                <add name="System.Net"/>
                        </listeners>
                </source>
        <source name="System.Net.Cache">
                        <listeners>
                <add name="System.Net"/>
                        </listeners>
                </source>
                </sources>
        <sharedListeners>
                <add
                 name="System.Net"
                 type="System.Diagnostics.TextWriterTraceListener"
                  initializeData="System.Net.trace.log"
                 traceOutputOptions = "ProcessId, DateTime"
                />
        </sharedListeners>
    <switches>
        <add name="System.Net" value="Verbose" />
        <add name="System.Net.Sockets" value="Verbose" />
        <add name="System.Net.Cache" value="Verbose" />
        <add name="System.Net.HttpListener" value="Verbose" />
    </switches>
    </system.diagnostics>
</configuration>

Hint.  If Verbose is too verbose you can change that value to one of these:

Critical, Error, Verbose, Warning, and Information.

Ref: How to: Configure Network Tracing

If you find this useful, please drop me a note in the comments!

Comments

  • Anonymous
    January 21, 2015
    This was very helpful.

  • Anonymous
    January 13, 2016
    If you're trying to debug web requests, make sure to add System.Net.Http to the list

  • Anonymous
    October 11, 2016
    If the config also has a "configSections" section, be sure the "system.diagnostics" section goes below it to avoid errors.