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:
- Display Name
- 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.
- TraceLevel.Error: Output error-handling messages.
- TraceLevel.Info Output: informational messages, warnings, and error-handling messages.
- TraceLevel.Off: Output no tracing and debugging messages.
- TraceLevel.Verbose: Output all debugging and tracing messages.
- 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:
- C# Frequently Asked Questions - 1
- C# Frequently Asked Questions - 2
- C# Frequently Asked Questions - 3
- Difference between a Debug and Release build
- Difference between normal DLL and .Net DLL
- What is an Interface in C#
- Difference between Abstract Class and Interface
- Difference between a thread and a process
- What is .Net Delegates
- Differences between a control and a component
- Differences between Stack and Heap
- What is .Net Reflection
- Globalization and Localization
- What is .Net serialization
- Difference between web service and .net remoting
- Difference between managed and unmanaged code
- Difference between Shallow copy and Deep copy
- Use of System.Environment Class
- What is the difference between private and shared assembly?
- Does the .NET have in-built support for serialization?
- How to properly stop the Thread in C#?
- Why is XmlSerializer so slow?
- How many types of Jit Compilers?