System.Web Namespace TraceContext Class
Indicates whether tracing is enabled for the current Web request.
[ VB ]
Public Property IsEnabled As Boolean
[ C# ]
public bool IsEnabled {get; set;}
[ C++ ]
public: __property bool get_IsEnabled ( );
public: __property void set_IsEnabled ( bool );
[ JScript ]
public function get IsEnabled ( ) : Boolean;
public function set IsEnabled ( Boolean );
true if tracing is enabled; otherwise, false. The default is the setting of the enabled attribute in the <trace> section of a configuration file. If enabled is not set in a configuration file, the default is false.
Use this flag to check whether your page or application should output tracing information before it writes anything to the trace log. You can set this property to true for a page by including a trace="true" attribute in the @ Page directive. To set the property to true for an entire application, set it in the application's web.config file.
NOTE: If you set this property to true for an entire application, you must explicitly set this property to false for any page in the application for which you do not want tracing information displayed.
The following example [ VB, C++ ] demonstrates how you can check to see if tracing is enabled for a page before writing debugging code to it. The code iterates through the rows in a dataset, writing trace statements for each row in that dataset.
[ VB ]
If ( Context.IsEnabled )
Dim I As Integer
For I = 0 To DS.Tables ( "Categories" ).Rows.Count - 1
Trace.Write ( "ProductCategory", _
DS.Tables ( "Categories" ).Rows ( I ) ( 0 ).ToString ( ) )
Next
End If
[ C++ ]
if ( Context->IsEnabled ) {
for ( int i=0; i<ds->get_Tables ( ) ->get_Item ( S"Categories" ) ->get_Rows ( ) ->get_Count ( ); i++ ) {
Trace::Write ( S"ProductCategory",ds->get_Tables ( ) ->get_Item ( S"Categories" ) ->get_Rows ( ) ->get_Item ( i ) ->get_Item ( 0 ) ->ToString ( ) );
}
}
TraceContext Members TraceMode Enumeration