
226
|
Chapter 10: Error Handling, Debugging, and Tracing
This is the Title of the Book, eMatter Edition
Copyright © 2008 O’Reilly & Associates, Inc. All rights reserved.
More importantly, you can also write to the trace output using the Trace.Write
and Trace.Warn methods, which are exposed by the Trace property of the
Page
class. These methods can now be used in place of Response.Write when you
determine the value of a variable on a page at a certain point in page execution
or write out a notification that a certain point in the page has been hit. With
Trace.Write or Trace.Warn, once you’ve disabled tracing, you can leave the
statements in your code and you don’t have to worry about anyone seeing the
output. If you’ve ever deployed a page to production without removing or
commenting out your Response.Write statements used for debugging, you’ll be
grateful for this feature.
Page-Level Tracing
Enabling tracing at the page level is very simple. Simply add the Trace attribute to
the
@ Page directive and set its value to True, as shown in the following code
snippet:
<%@ Page Language="VB" Trace="True" %>
This provides a quick and easy way to get an overview of what’s going on for a
given page. The output from a page with tracing enabled looks similar to
Figure 10-8.
One downside to enabling tracing at the page level is that if you use it with many
pages, it’s more work to add and remove the
Trace attribute