Main Page

  Previous Section Next Section


System.Web (system.web.dll)sealed class

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.

public sealed class TraceContext {
// Public Constructors
   public TraceContext(HttpContext context);
// Public Instance Properties
   public bool IsEnabled{set; get; }
   public TraceMode TraceMode{set; get; }
// Public Instance Methods
   public void Warn(string message);
   public void Warn(string category, string message);
   public void Warn(string category, string message, Exception errorInfo);
   public void Write(string message);
   public void Write(string category, string message);
   public void Write(string category, string message, Exception errorInfo);

Returned By

HttpContext.Trace, System.Web.UI.Page.Trace, System.Web.UI.UserControl.Trace

      Previous Section Next Section