The .NET Framework Class Library (FCL) contains many classes to obtain diagnostic information about your application, 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 chapter contains recipes for instrumenting your application with debug/trace information, 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 configuration 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 performance 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 information to be dumped to a file. This file can be inspected to help pinpoint the real problem. This usage is discussed at length in Recipes 8.1 and
Since both the
Trace classes contain the same members with the same names, they can be interchanged in your code by renaming
Trace and vice ...