|
|
How Do I...Instrument a small application with tracing?Trace instrumentation enables developers and administrators to monitor applications running in real-life settings (as opposed to running in a debugger). Sometimes using a debugger can hide bugs and obscure some performance and threading problems. Tracing is a very important monitoring and debugging tool for distributed, multitier applications. Such applications often contain problems that you can only observe when the application is under a heavy load, and in the inherent randomness of a real-life environment.This sample illustrates the basics of instrumenting applications with tracing. After running it, take a look at the source code. You will see how easy it is to add simple instrumentation to your applications. You have to compile your instrumented applications with trace or debug compiler directives enabled. Otherwise, all calls to Trace or Debug (respectively) are ignored during compilation. Before running the application, create a configuration
file - TraceDemo.exe.config - in the same directory as the
executable, and set
<?xml version="1.0" encoding="UTF-8" ?>
<configuration>
<system.diagnostics>
<switches>
<!-- Set value property of the TraceMethods switch to:
0 (false) or 1 (true) -->
<add name="TraceMethods" value="1" />
<!-- Set value property of the Arithmetic switch to:
1(error), 2(warning), 3(info), 4(verbose) -->
<add name="Arithmetic" value="4" />
</switches>
<trace autoflush="false" indentsize="4" />
</system.diagnostics>
</configuration>
Note: DBMon.exe is available from the Windows Platform SDK on the Microsoft Developer Network website. Example
|