How to: Configure Network Tracing


The application or computer configuration file holds the settings that determine the format and content of network traces. Before performing this procedure, be sure tracing is enabled. For information about enabling tracing, see Enabling Network Tracing.

The computer configuration file, machine.config, is stored in the %Windir%\Microsoft.NET\Framework folder in the directory where Windows was installed. There is a separate machine.config file in the folders under %Windir%\Microsoft.NET\Framework for each version of the .NET Framework installed on the computer (for example, C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\machine.config).

These settings can also be made in the configuration file for the application, which has precedence over the computer configuration file.

To configure network tracing

  • Add the following lines to the appropriate configuration file. The values and options for these settings are described in the tables below.

          <source name="System.Net" tracemode="includehex" maxdatasize="1024">  
              <add name="System.Net"/>  
          <source name="System.Net.Cache">  
              <add name="System.Net"/>  
          <source name="System.Net.Http">  
              <add name="System.Net"/>  
          <source name="System.Net.Sockets">  
              <add name="System.Net"/>  
          <source name="System.Net.WebSockets">  
              <add name="System.Net"/>  
          <add name="System.Net" value="Verbose"/>  
          <add name="System.Net.Cache" value="Verbose"/>  
          <add name="System.Net.Http" value="Verbose"/>  
          <add name="System.Net.Sockets" value="Verbose"/>  
          <add name="System.Net.WebSockets" value="Verbose"/>  
          <add name="System.Net"  
        <trace autoflush="true"/>  

When you add a name to the <switches> block, the trace output includes information from some methods related to the name. The following table describes the output.

NameOutput from
System.Net.SocketsSome public methods of the Socket, TcpListener, TcpClient, and Dns classes
System.NetSome public methods of the HttpWebRequest, HttpWebResponse, FtpWebRequest, and FtpWebResponse classes, and SSL debug information (invalid certificates, missing issuers list, and client certificate errors.)
System.Net.HttpListenerSome public methods of the HttpListener, HttpListenerRequest, and HttpListenerResponse classes.
System.Net.CacheSome private and internal methods in System.Net.Cache.
System.Net.HttpSome public methods of the HttpClient, DelegatingHandler, HttpClientHandler, HttpMessageHandler, MessageProcessingHandler, and WebRequestHandler classes.
System.Net.WebSockets.WebSocketSome public methods of the ClientWebSocket and WebSocket classes.

The attributes listed in the following table configure trace output.

Attribute nameAttribute value
ValueRequired String attribute. Sets the verbosity of the output. Legitimate values are Critical, Error, Verbose, Warning, and Information.

This attribute must be set on the <add name> element of the <switches> element as shown in the example. An exception is thrown if this attribute is set on the <source> element.
maxdatasizeOptional Int32 attribute. Sets the maximum number of bytes of network data included in each line trace. The default value is 1024.

This attribute must be set on the <source> element as shown in the example. An exception is thrown if this attribute is set on an element under the <switches> element.
TracemodeOptional String attribute. Set to includehex to show protocol traces in hexadecimal and text format. Set to protocolonly to show only text. The default value is includehex.

This attribute must be set on the <switches> element as shown in the example. An exception is thrown if this attribute is set on an element under the <source> element.

Interpreting Network Tracing
Network Tracing in the .NET Framework
Enabling Network Tracing
Introduction to Instrumentation and Tracing