
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
434
|
Chapter 8: Diagnostics
reproduce on your development machine. Knowing this, you want an application
with built-in instrumentation that’s off by default but can easily be turned on when
you need it.
Solution
Use the Trace class for any tracing code that you might need to turn on after your
application has been deployed. To turn on tracing at a client’s site, provide the client
with an application configuration file such as this one:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.diagnostics>
<switches>
<add name="DatabaseSwitch" value="4"/>
<!-- 4 == TraceLevel.Verbose -->
</switches>
<trace autoflush = "true" indentsize = "2">
<listeners>
<add name = "MyListener"
type = "System.Diagnostics.TextWriterTraceListener"
initializeData = " MyFileName.log"/>
</listeners>
</trace>
</system.diagnostics>
</configuration>
Discussion
Allowing tracing code to be enabled and used at a client site can be extremely useful
when debugging problems in release code. This technique is even more useful when
the problem cannot easily be reproduced in-house. For this reason, it is—in some
cases—a wise practice to use the
Trace class instead of the Debug class when adding
tracing code to your application.
To control the trace output at a client site, you can use an XML config file. This XML ...