Controlling Tracing

You can control how much output is generated by using a switch object, which enables you to place a lot of detailed tracing code in your program and determine at runtime how much is going to be logged. There are two standard switch classes provided in System.Diagnostics, TraceSwitch and BooleanSwitch. You can derive your own from the Switch base class if necessary.

Switch objects are especially useful in that they can read their settings from an external text file, so it is easy to tailor the amount of trace output you're going to get without having to recompile the code. You can also use switch objects to control which output is sent to listeners, so you could arrange for a subset of the trace information to be logged to the screen and have much more information saved to a file.

0 0

Post a comment