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 TraceMethods and
Arithmetic to
the values of your choice as shown below:
<?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>
Next, open a command line window
and run the Debug Monitor utility (DbMon.exe). You will be able to see any debug and trace messages coming
from any application running on your system.
Note: DBMon.exe is available from the Windows Platform SDK on the Microsoft Developer Network website.
Example
VB TraceDemo.exe
Microsoft .NET Framework SDK QuickStart Tutorials Version 2.0
Copyright � 2005 Microsoft Corporation. All rights reserved.
|