
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
433
Chapter 8
CHAPTER 8
Diagnostics
8.0 Introduction
The FCL contains many classes to obtain diagnostic information about your applica-
tion, as well as the environment it is running in. In fact, there are so many classes
that a namespace,
System.Diagnostics, was created to contain all of them. This chap-
ter contains recipes for instrumenting your application with debug/trace informa-
tion, obtaining process information, using the built-in event log, and taking
advantage of performance counters.
Debugging (using the
Debug class) is turned on by default in debug builds only, and
tracing (using the
Trace class) is turned on by default in both debug and release builds.
These defaults allow you to ship your application instrumented with tracing code using
the
Trace class. You ship your code with tracing compiled in but turned off in the con-
figuration so that the tracing code is not called (for performance reasons) unless it is a
server-side application (where the value of the instrumentation may outweigh the per-
formance hit). If a problem that you cannot re-create on your development computer
occurs on a production machine, you can enable tracing and allow the tracing informa-
tion to be dumped to a file. This file can be inspected to help pinpoint the real prob-
lem. This usage is discussed ...