Welcome   |  ASP.NET   |  Web Services   |  How Do I...?   |  Class Browser  | WPF Quick Starts
  |   I want my samples in...   

How Do I...? Common Tasks QuickStart Tutorial

Go To...

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

C# TraceDemo.exe
View Source

[This sample can be found at M:\web\users\sites\AspnetQuickStart\v2.0\QuickStart\howto\samples\Services\Tracing\TraceDemo\
To build this sample, open the SDK command prompt and navigate to the above path. Build the sample using the build tool msbuild passing the solution file as the first parameter: msbuild mySample.sln. The compiled executable will be found in the sub directory \bin directory.]




Microsoft .NET Framework SDK QuickStart Tutorials Version 2.0
Copyright � 2005 Microsoft Corporation. All rights reserved.


Hosted by MaximumASP | Found a broken link? | Contact Us | Terms and conditions | Privacy Policy | Advertise with us
� 2000 - 2010  Mindcracker LLC. All Rights Reserved