System.Diagnostics.TraceSwitcher

System.Diagnostics.TraceSwitch Class provides a multilevel switch to control tracing and debug output without recompiling your code. The tracing dumps can be quite verbose. For applications that are constantly running you run the risk of overloading the machine and the hard drive. TraceSwitch does not directly control the Trace statements, you have to pass one of its properties into a WriteLineIf or WriteIf method.

The TraceSwitch constructor take three values:

  1. Display Name
  2. Description
  3. Default Trace Value
The default value is 0 You can set the level of a TraceSwitch through the application configuration file and then use the configured TraceSwitch level in your application. Alternately, you can create a TraceSwitch in your code and set the level directly to instrument a specific section of code. Five levels range from None to Verbose, allowing you to fine-tune the tracing activities.
  1. TraceLevel.Error: Output error-handling messages.
  2. TraceLevel.Info Output: informational messages, warnings, and error-handling messages.
  3. TraceLevel.Off: Output no tracing and debugging messages.
  4. TraceLevel.Verbose: Output all debugging and tracing messages.
  5. TraceLevel.Warning: Output warnings and error-handling messages.
To configure a TraceSwitch , edit the application configuration file for your application. In this file, you can add or remove a switch, set a switch's value, or clear all the switches previously set by the application. The configuration file should be formatted like the following example:
configure a TraceSwitch c# asp.net vb.net