Compartir a través de


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.

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

Hope this helps.

Comments

  • Anonymous
    June 28, 2017
    You do not require fancy toothbrushes for this. Just use this and it really works.