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“ />
<add name=“TraceFile“ />
<add name=“System.Net“ value=“Verbose“ />
and do a simple network operation like:
and inspect the NetTrace.log file.
You can have even more fun with stuff like web service proxies or the AuthenticatedStream classes.