Name

Trace

Synopsis

TraceContext = Page.Trace

Returns the TraceContext object for the current web request. Tracing provides the details about the execution of the web request. The TraceContext class includes the following members:

Member

Description

IsEnabled

Indicates whether tracing is enabled for the current page.

TraceMode

A member of the TraceMode enumeration that indicates how items should be sorted. Possible values are SortByCategory and SortByTime. The latter is the default value defined in machine.config.

Warn method

Writes a message to the trace log using red text.

Write method

Writes a message to the trace log.

Parameters

TraceContext

An instance of the TraceContext class.

Example

The example turns tracing on programmatically by using the Trace property of the Page class:

Sub Page_Load(  )
   If Trace.IsEnabled = True Then
      Message.Text = "Tracing is enabled."
   Else
      Message.Text = "Tracing is not enabled."
   End If
End Sub

Notes

As with the Request and Response properties, while you can retrieve a local reference to the TraceContext instance associated with the request, it is more common to access this instance directly through the Trace property, as shown in the following example. For more information on application tracing, see Chapter 10.

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.