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 or C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\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"  
            traceOutputOptions="ProcessId, DateTime" 
        <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.

Name Output from
System.Net.Sockets Some public methods of the Socket, TcpListener, TcpClient, and Dns classes
System.Net Some 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.HttpListener Some public methods of the HttpListener, HttpListenerRequest, and HttpListenerResponse classes.
System.Net.Cache Some private and internal methods in System.Net.Cache.
System.Net.Http Some public methods of the HttpClient, DelegatingHandler, HttpClientHandler, HttpMessageHandler, MessageProcessingHandler, and WebRequestHandler classes.
System.Net.WebSockets.WebSocket Some public methods of the ClientWebSocket and WebSocket classes.

The attributes listed in the following table configure trace output.

Attribute name Attribute value
Value Required 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.
maxdatasize Optional 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.
Tracemode Optional 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.

See also