Tracing and Instrumenting Applications
Tracing is a way for you to monitor the execution of your application while it is running. You can add tracing and debugging instrumentation to your .NET Framework application when you develop it, and you can use that instrumentation both while you are developing the application and after you have deployed it. You can use the System.Diagnostics.Trace, System.Diagnostics.Debug, and System.Diagnostics.TraceSource classes to record information about errors and application execution in logs, text files, or other devices for later analysis.
Instrumenting your application by placing trace statements at strategic locations in your code is especially useful for distributed applications. By using trace statements you can instrument an application not only to display information when things go wrong, but also to monitor how well the application is performing.
The TraceSource class provides enhanced tracing features and can be used in place of the static methods of the older Trace and Debug tracing classes. The familiar Trace and Debug classes are still widely used, but the TraceSource class is recommended for new tracing commands, such as TraceEvent and TraceData.
The Trace and Debug classes are identical, except that procedures and functions of the Trace class are compiled by default into release builds, but those of the Debug class are not.
The following topics provide additional information on using instrumentation in your applications.
In This Section
Introduction to Instrumentation and Tracing
Provides an overview of basic concepts of instrumentation and code tracing.Code Contracts
Explains how to specify preconditions, postconditions, and object invariants for marking and analyzing your code.Trace Switches
Describes the use of switches to filter tracing messages based on complex criteria.Trace Listeners
Describes the use of listeners to route tracing messages to particular output targets.How to: Trace Code in an Application
Describes the major steps involved in instrumentation and tracing.How to: Add Trace Statements to Application Code
Provides several techniques for using tracing and debugging messages in your applications.How to: Compile Conditionally with Trace and Debug
Gives directions for including tracing options in compiled applications.How to: Create and Initialize Trace Sources
Gives directions for the use of the TraceSource class.
Reference
TraceSource
Provides a set of methods and properties that help trace the execution of code and associate trace messages with their source. This is the recommended alternative to the older Trace and Debug classes.Trace
Provides a set of methods and properties that help you trace the execution of your code.Debug
Provides a set of methods and properties that help debug your code.
Related Sections
How to: Use TraceSource and Filters with Trace Listeners
Describes the use of a TraceSource coupled with an application configuration file.How to: Create and Initialize Trace Sources
Describes the use of a TraceSource with and without an application configuration file.Debugging Preparation: C#, F#, and Visual Basic Project Types
Provides links to managed code debugging topics.