Provides a multi-level switch to enable or disable tracing and debug output for a compiled application or framework.
[Visual Basic] Public Class TraceSwitch Inherits Switch [C#] public class TraceSwitch : Switch [C++] public __gc class TraceSwitch : public Switch [JScript] public class TraceSwitch extends Switch
You can use the trace levels to filter out messages based on their importance. The switch can be enabled or disabled from code, from an environment variable, from a registry setting, or from a debug configuration file.
When the System.Diagnostics.TraceSwitch constructor cannot find initial switch settings in the registry or in environmental variables, the Level of the new switch is set to Off.
To specify the TraceLevel of the switch, call the Level property with one of the TraceLevel enumeration values. The Level also can be set by an external setting file. Setting the Level property updates the other properties in this class.
The following properties test the TraceLevel of the switch:
For more information on instrumenting your application, see <DebugTopicTBD>.
Namespace: System.Diagnostics
Assembly: System.dll
The following example creates a new TraceSwitch. It checks the switch level before outputting debugging messages.
[Visual Basic]
Dim arithmeticSwitch As TraceSwitch Assign arithmeticSwitch = New TraceSwitch("arithmeticSwitch","tracing arithmetic operations") ... If b = 0 Then DivideIntegers = 0; If arithmeticSwitch.OutputError Then Debug.WriteLine "division by zero in DivideIntegers" Exit Function End If DivideIntegers = a/b If arithmeticSwitch.OutputVerbose Then Debug.WriteLine "DivideIntegers resulted in " & a/b End If
TraceSwitch Members | System.Diagnostics Namespace | Switch | BooleanSwitch | TraceLevel | Debug | Trace