Diagnostics: How to enable debug tracing for System.Net.Mail API?

You can enable the following trace switches in your application config file, so that you can enable tracing for The System.Net.Mail library/API. This will log the contents of the SMTP session to a file. To send traces to a log file, add the following node to the <system.diagnostics> node of the appropriate configuration file (application or machine). You can change the name of the file (trace.log) to suit your needs, like what i did below as “System.Net.trace.log”.

So the below example will log the SMTP session in a file, "System.Net.trace.log". You can have a look it, which will be helpful for your detailed debugging/troubleshooting purpose.

   <system.diagnostics>     <trace autoflush="true" />
      <source name="System.Net" >
           <add name="MyTraceFile"/>
      <source name="System.Net.Sockets">
           <add name="MyTraceFile"/>
       <add  name="MyTraceFile" type="System.Diagnostics.TextWriterTraceListener" initializeData="System.Net.trace.log"   />
       <add name="System.Net" value="Verbose" />
       <add name="System.Net.Sockets" value="Verbose" />

Hope this helps.

Comments (1)
  1. painter decorator says:

    You do not require fancy toothbrushes for this. Just use this and it really works.

Comments are closed.

Skip to main content