Chapter 12: Tracing and Diagnostics


Overview

The .NET Framework offers an incredibly extensible tracing infrastructure, all the way from basic asserts to industrial strength event logging. This chapter will take a look at what trace functionality is available out of the box and what you can build on your own. We'll also see how to filter, redirect, and customize the tracing infrastructure without touching a line of code, via the powerful configuration subsystem. Writing and reading messages to and from the Windows Event Log, for instance, is as simple as adding a few lines to your configuration file.

Although we don't venture beyond it in great detail, tracing is certainly not the extent of the .NET Framework's support for diagnostics:

  • Performance counters can be used to report back quantitative metrics about what's going on inside your program and can be instrumental in identifying bottlenecks, leaks, or opportunities for fine-tuning. In fact, the CLR itself is constantly reporting back many interesting metrics that you can view and analyze using existing tools. You can even create custom performance counters to report information specific to your application.

  • The Windows Event Log is useful for nondebug tracing and error information, both for you while debugging your own program and or system administrators managing deployed applications. The tracing infrastructure surfaces it as an easy choice of where to log trace output, but there is also a feature-rich set of APIs with which you can directly interact with the Event Log.

  • Lastly, a set of tools have support built right into the runtime, enabling you to debug and profile your application as it is running (you can even modify its contents with the new 2.0 Edit & Continue feature). The runtime itself also publishes events for common problems, a feature also new to 2.0 called Managed Debugging Assistants (MDAs for short).

Making intelligent use of the tracing facilities available can help to reduce the number of commented out Console.WriteLines scattered throughout your program. With some of the improvements in version 2.0, the tracing subsystem is more approachable and easier to use than ever before.




Professional. NET Framework 2.0
Professional .NET Framework 2.0 (Programmer to Programmer)
ISBN: 0764571354
EAN: 2147483647
Year: N/A
Pages: 116
Authors: Joe Duffy

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net