Tracing System.Net

Often, the last secret weapon you have when troubleshooting networked applications is a packet sniffer. If you ever need one, don’t bother looking around, grab a copy of ethereal.

But there are also situations where sniffing is not easily possible, e.g. when you are using transport security like SSL, when you use the loobback address or you simply can’t install a sniffer on the machine.

In .NET 2.0 you can enable tracing for the whole .NET network stack (aka System.Net). This can be done on a per-application basis using a configuration file. The trace output is really interesting. It shows the process and thread ID, the payload of the data (regardless of transport security as tracing happens much earlier) and lots of interesting protocol information.

To see what’s going on in the network stack simply add the following to a configuration file:



  <trace autoflush=true />


    <source name=System.Net>


        <add name=TraceFile />









      initializeData=NetTrace.log />




    <add name=System.Net value=Verbose />




and do a simple network operation like:

new WebClient().DownloadData(;);

and inspect the NetTrace.log file.

You can have even more fun with stuff like web service proxies or the AuthenticatedStream classes.

Very useful!


This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s