ASP+ aids the debugging and testing process by providing a trace capability that does two things when enabled:
The performance data and the developer-specified messages (if any) are injected into the HTML output stream to the client to help clarify what is occurring as the framework processes a page request.
The trace capability is encapsulated in the TraceContext class, which is exposed as the Page.Trace property of the Page class.
Enabling Tracing
The trace capability must be enabled prior to use. You enable tracing by setting the Trace attribute of the @ Page directive to true (it is false by default):
<%@ Page Language="VB" Trace="true" %>
The Trace attribute sets the value of the TraceContext.IsEnabled boolean.
Inserting and Organizing Trace Messages
There are two methods you can use to insert custom messages: TraceContext.Write and TraceContext.Warn. In their simplest form, each method takes two string arguments:
public void Write( string category, string message ) public void Warn( string category, string message )
The category
argument is used to organize messages. For example:
<%@ Page Language="VB" Trace="true" %> <html> <body> <% Trace.Write( "MyCategory", "This message is mine." ) Trace.Write( "YourCategory", "This message is yours." ) %> </body> </html>
The difference between Write and Warn is that Warn uses a red font in its output.
Both Write and Warn have overloaded versions that take an additional argument of type Exception. You can use these versions in exception-handling code to display information about the exception.
Sorting Trace Messages
The TraceContext class contains a TraceMode property that defines the way that trace messages are sorted in the page output. TraceMode is of type TraceModeEnum. There are three possible values:
category
argument to the Write and Warn methodsSee Also