Trace buttons allow you to enable, disable, and then filter tracing output. They’re items which exist on your code and can be configured through the .config file. There are 3 Kinds of trace switches supplied from the .NET Framework: the BooleanSwitch course, the TraceSwitch course, as well as the SourceSwitch course. The BooleanSwitch course functions as a toggle switch, either allowing or disabling many different trace statements. The TraceSwitch and SourceSwitch courses enable you to allow a trace switch to get a certain tracing level so the Trace or TraceSource messages given for this level and all levels below it look. Should you disable the change, the trace messages won’t appear. These classes derive from the subjective (MustInherit) course Switch, as if any user-developed switches.

Trace switches may be handy for filtering info. By way of instance, you may want to observe every tracing message at a data entry module, but merely error messages in the remaining portion of the program. If that’s the event, you would use 1 trace button for the data entry module and a single switch for the remaining portion of the program. By employing this .config document to configure the buttons to the ideal settings, you can control what kinds of trace message you’ve got.

Usually, a set up application is implemented with its buttons disabled, so users don’t observe a good deal of insignificant trace messages appearing on a display or filling a log file since the program runs. If an issue arises during program implementation, you can halt the program, enable the buttons, and restart the program.

To use a change you have to first produce a switch thing in the BooleanSwitch course, a TraceSwitch course, or a developer-defined change course. To learn more about producing developer-defined switches, visit the Switch course from the .NET Framework benchmark. You then decide on a configuration value that defines if the change thing is to be utilized. Then you examine the setting of this change thing in different Trace (or even Debug) tracing methods.

Trace Levels

A TraceSwitch thing has four properties which yield Boolean values indicating if the change has been set to at a Specific amount:

TraceSwitch.TraceError

TraceSwitch.TraceWarning

TraceSwitch.TraceInfo

TraceSwitch.TraceVerbose

Levels permit you to restrict the total amount of tracing data you get to only that data required to fix a problem. You define the degree of detail you need on your tracing output signal by placing and configuring trace buttons to the proper trace amount.

It’s completely your responsibility to choose what type of message to connect with every degree. Usually, the material of unread messages is dependent on what you connect with every degree, but you decide the differences between amounts. You may want to present in depth descriptions of an issue at level 3 (Info), as an instance, but provide just a mistake reference number at level 1 (Error). It’s completely your responsibility to choose what strategy works best on your program.

The next table lists the degree of this TraceLevel enumeration and their worth.

The TraceSwitch possessions indicate the maximum trace level for your change. In other words, tracing information is written to your amount specified and for many lower levels. As an instance, if TraceInfo is authentic , subsequently TraceError and TraceWarning will also be authentic however TraceVerbose may be untrue .

These possessions are read-only. The TraceSwitch thing automatically sets them as soon as the TraceLevel land is set. As an instance:

Fresh System.Diagnostics.TraceSwitch(“SwitchOne”,”The first switch”); myTraceSwitch.Level = System.Diagnostics.TraceLevel.Info; // This message box shows true, since placing the amount to // TraceLevel.Info sets all reduced degrees to accurate also.
Developer-Defined Switches

Along with supplying BooleanSwitch and TraceSwitch, it is possible to specify your personal switches by inheriting in the Switch class and overriding the base class procedures with customized approaches. To learn more about producing developer-defined switches, visit the Switch course from the .NET Framework benchmark.