Thursday, August 27, 2009

Tracing with System.Net

In my old blog, I had written a config file that shows how to enable trace logging for System.Net. Since it is useful, here is the config file again..

<?xml version="1.0" encoding="UTF-8" ?>

    <configuration>
    <system.diagnostics>
    <trace autoflush="true" />

    <sources>
    <source name="System.Net">

    <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"
        />
    </sharedListeners>
    <switches>
        <add name="System.Net" value="Verbose" />
        <add name="System.Net.Sockets" value="Verbose" />               
        <add name="System.Net.Cache" value="Verbose" />
    </switches>
</system.diagnostics>
</configuration>

NOTE: If you are doing logging inside of the ASP.NET process, make sure to give the ASP.NET process identity WRITE permissions to the directory where you want the log to be written.