This is an old revision of the document!


Debugging
Using System.Diagnostics

Add the following to the app.exe.config file (must reside in the same folder and the app.exe):

<configuration>
...
<system.diagnostics>
    <sources>
      <source name="srcMyAppDebug" switchName="SourceSwitch" >
        <listeners>
          <add name="textListener" />
        </listeners>
      </source>
    </sources>
    <switches>
      <add name="SourceSwitch" value="All" />
    </switches>
    <sharedListeners>
      <add name="myTextListener"
           type="System.Diagnostics.TextWriterTraceListener"
           initializeData="Debug.txt" />
    </sharedListeners>
    <trace autoflush="true" indentsize="4"></trace>
</system.diagnostics>
 
</configuration>

The listener could also be:

  <listeners>
     <add name="myXmlListener"
          type="System.Diagnostics.XmlWriterTraceListener"
          initializeData= "Debug.xml" />
  </listeners>

To write to the event log:

System.Diagnostics.Trace.TraceInformation("Some operation here: Hello World");
System.Diagnostics.Trace.TraceError("Error: Something failed here.");

Alternatively, and more flexible:

TraceSource srcMyApp = new TraceSource("srcMyAppp");
srcMyApp.TraceInformation("Some operation here: Hello World");
srcMyApp.TraceEvent(TraceEventType.Error, 0, "Error: Something failed here.");