Name

TraceContext

Synopsis

The TraceContext class allows you display trace messages that can help you debug ASP.NET applications. To enable tracing for a specific page, insert the page directive Trace="True" in the ASPX file or set the IsEnabled property of the TraceContext class in your code-behind module.

The TraceContext class provides two methods: Write() and Warn(). Both display a message in the current page’s trace log, but Warn() uses red lettering that is meant to indicate exception information. You can invoke the Write() or Warn() method with a category string and message string. Often, the category string indicates the position in the code (“In FunctionA”), while the message string indicates specific information (“Exception while opening database”). Additionally, an overloaded version of Write() and Warn() allows you supply an exception object that ASP.NET will use to extract the appropriate information. Even if you don’t use the Write() and Warn() methods, ASP.NET automatically inserts trace log entries to indicate standard events, and appends a great deal of information after the list of trace message, including performance data, tree-structure information, and state management content.

The TraceContext class is provided as the built-in Trace object. You can use the web.config file to set additional tracing options like the default TraceMode, and enable application-wide tracing. Application-wide tracing can be displayed on the page or cached exclusively in memory. ...

Get ASP.NET in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.