# 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 more information, see Enable network tracing.

The computer configuration file, machine.config, is stored in the %windir%\Microsoft.NET\Framework folder. 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\Config\machine.config
• 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.

## Configure network tracing

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.

<configuration>
<system.diagnostics>
<sources>
<source name="System.Net" tracemode="includehex" maxdatasize="1024">
<listeners>
</listeners>
</source>
<source name="System.Net.Cache">
<listeners>
</listeners>
</source>
<source name="System.Net.Http">
<listeners>
</listeners>
</source>
<source name="System.Net.Sockets">
<listeners>
</listeners>
</source>
<source name="System.Net.WebSockets">
<listeners>
</listeners>
</source>
</sources>
<switches>
</switches>
<sharedListeners>
type="System.Diagnostics.TextWriterTraceListener"
initializeData="network.log"
traceOutputOptions="ProcessId, DateTime"
/>
</sharedListeners>
<trace autoflush="true"/>
</system.diagnostics>
</configuration>


### Trace output from methods

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.

### Trace output attributes

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 element of the switches element. An exception is thrown if this attribute is set on the source element.

Example: <add name="System.Net" value="Verbose"/>
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. An exception is thrown if this attribute is set on an element under the switches element.

Example: <source name="System.Net" tracemode="includehex" maxdatasize="1024">
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 source element. An exception is thrown if this attribute is set on an element under the switches element.

Example: <source name="System.Net" tracemode="includehex" maxdatasize="1024">