
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Providing Fine-Grained Control over Debugging/Tracing Output
|
439
Creating these switches at this point results in every switch’s level being set to zero.
To turn them on, use an application configuration file, shown here:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.diagnostics>
<switches>
<clear/>
<add name="DatabaseFilter" value="4" />
<add name="UIFilter" value="0" />
<add name="ExceptionFilter" value="1" />
</switches>
</system.diagnostics>
</configuration>
This XML file contains a nested tag called switches. This tag defines switch names
and sets a value indicating the level of the switch. The
TraceSwitch class accepts the
five predefined trace levels shown in Table 8-1. The level of the
TraceSwitch can be
set through code, but that defeats the flexibility of using a configuration file.
For more information on the application configuration file, see Recipe 8.1.
Discussion
Turning tracing on or off involves the BooleanSwitch class. When the BooleanSwitch
is created, it attempts to locate a switch with the same name as the displayName
parameter in either the machine.config or application configuration file. If it cannot
locate this name in either file,
BooleanSwitch.Enabled is set to false.
The application configuration file for a WinForms- or Console-based application ...