Add Console.Out to TextWriterTraceListener : Debug « Development « C# / CSharp Tutorial






#define DEBUG

using System;
using System.Globalization;
using System.Diagnostics;

class MainClass
{
  public static void Main() 
  {
    TextWriterTraceListener tl = new TextWriterTraceListener(Console.Out);
    Debug.Listeners.Add(tl);

    Debug.WriteLine("Starting Main()");

    Debug.Assert(1 == 2, "1==2");

    Debug.WriteLine("Exiting Main()");
  }
}
Starting Main()
Fail: 1==2
Exiting Main()








14.24.Debug
14.24.1.Debug Assert
14.24.2.Add Console.Out to TextWriterTraceListener
14.24.3.Set up a TraceListener to a file
14.24.4.Add EventLogTraceListener to Debug.Listener
14.24.5.Debug and Trace Output
14.24.6.Using Switches to Control Debug and Trace: BooleanSwitch
14.24.7.Using Switches to Control Debug and Trace: TraceSwitch