Use Trace Switch : Trace « Development « C# / CSharp Tutorial






using System;
using System.Diagnostics;

class TracingExample
{
  static void Main(string[] args)
  {
    TraceSwitch General = new TraceSwitch("General", "Application Switch");

    Trace.WriteLineIf(General.TraceError, "General - Error Tracing Enabled");
    Trace.WriteLineIf(General.TraceWarning, "General - Warning Tracing Enabled");
    Trace.WriteLineIf(General.TraceInfo, "General - Info Tracing Enabled");
    Trace.WriteLineIf(General.TraceVerbose, "General - Verbose Tracing Enabled");

  }
}


/*
<?xml version="1.0" encoding="utf-8" ?> 
<configuration>
    <system.diagnostics>
        <switches>
            <add name="General" value="1" />

        </switches>
    </system.diagnostics>
</configuration>
*/








14.28.Trace
14.28.1.Tracing To Debugger
14.28.2.Trace Assert
14.28.3.Trace to console
14.28.4.Trace to a file
14.28.5.Tracing To EventLog
14.28.6.Use Trace Switch
14.28.7.Use Trace Switch defined in config file