Debug and Trace Output : Debug « Development « C# / CSharp Tutorial






// compile with: csc /r:system.dll file_1.cs
using System;
using System.Diagnostics;

class MyClass
{
    [Conditional("DEBUG")]
    public void VerifyState()
    {
        Debug.Assert(2 == 0, "Bad State");
    }
}

class MainClass
{
    public static void Main()
    {
        Debug.Listeners.Clear();
        Debug.Listeners.Add(new TextWriterTraceListener(Console.Out));
        MyClass c = new MyClass();
        
        c.VerifyState();
        c.VerifyState();
    }
}








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