Using Switches to Control Debug and Trace:TraceSwitch : Debug Trace « Development Class « C# / C Sharp

Using Switches to Control Debug and Trace:TraceSwitch

using System;
using System.Diagnostics;

class MyClass
    public MyClass(int i)
        this.i = i;
    public void VerifyState()
        Debug.WriteLineIf(debugOutput.TraceInfo, "VerifyState Start");
        "Starting field verification");
        if (debugOutput.TraceInfo)
        Debug.WriteLine("VerifyState End");
    static TraceSwitch    debugOutput = 
    new TraceSwitch("MyClassDebugOutput", "Control debug output");
    int i = 0;

public class TraceTraceSwitch
    public static void Main()
        Debug.Listeners.Add(new TextWriterTraceListener(Console.Out));
        MyClass c = new MyClass(1);


Related examples in the same category

1.Using BooleanSwitchUsing BooleanSwitch
2.Debug class
3.Debug and ProfileDebug and Profile
4.Trace to event log
5.Trace to debuger: writeline and flush
6.Trace class: listener and writeline
7.Tracing To A File
8.Tracing Example
9.demonstrates debug outputdemonstrates debug output
10.illustrate the use of the debuggerillustrate the use of the debugger
11.A simple demonstration of the Debug class
12.Demonstrate indenting debug messages
13.Demonstrates routing debug messages to a fileDemonstrates routing debug messages to a file
14.Defensive Programming:Conditional Methods
15.Debug and Trace Output
16.Using Switches to Control Debug and Trace:BooleanSwitch
17.Using Switches to Control Debug and Trace:User-Defined Switch
18.Object Dumper