home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 40 / IOPROG_40.ISO / SOFT / NETFrameworkSDK.exe / comsdk.cab / samples.exe / QuickStart / aspplus / doc / tracelogpage.aspx < prev    next >
Encoding:
Text File  |  2000-06-01  |  4.1 KB  |  91 lines

  1.  
  2. <%@ Register TagPrefix="Acme" TagName="SourceRef" Src="/quickstart/util/SrcRef.aspx"%>
  3.  
  4. <!-- #include virtual="/quickstart/aspplus/include/header.inc" -->
  5.  
  6. <h4>Trace Logging to Page Output</h4>
  7.  
  8. Page-level Tracing provides the ability to write debugging statements directly to a page's output, and conditionally execute 
  9. debugging code when tracing is enabled.  To enable Tracing for a page, include the following directive at the top of the page code:
  10. <p>
  11.  
  12. <div class="code"><pre>
  13. <%@ Page Trace="true"%>
  14. </pre></div>
  15.  
  16. Trace statements may also be organized by category using the <b>TraceMode</b> attribute of the Page directive.  
  17. If no TraceMode attribute is defined, the default value is "SortByTime".
  18.  
  19. <div class="code"><pre>
  20. <%@ Page Trace="true" TraceMode="SortByCategory" %>
  21. </pre></div>
  22.  
  23. <p>
  24. The following example shows the default output when Page-level Tracing is enabled.  Note that ASP+ inserts timing information for
  25. important places in the page's execution lifecycle:
  26. <p>
  27.  
  28. <Acme:SourceRef 
  29.   RunSample="/quickstart/aspplus/samples/trace/trace1.aspx" 
  30.   ViewSource="/quickstart/aspplus/samples/trace/trace1.src"
  31.   Icon="/quickstart/aspplus/images/pagetrace1.gif"
  32.   Caption="Trace1.aspx"
  33.   runat="server" />
  34.  
  35. <p>
  36. The Page exposes a <b>Trace</b> property (of type "TraceContext") which can be used to output debugging statements to the page output, provided tracing is enabled.
  37. Using the TraceContext, you can write debugging statements using the <b>Trace.Write</b> and <b>Trace.Warn</b> methods, which each take category
  38. and message strings as arguments.  Trace.Warn statements are identical to Trace.Write statements, except they are output in <span style="color:red">red</span>.
  39.  
  40. <div class="code"><pre>
  41. Trace.Write("Custom Trace","Beginning User Code...");
  42. ...
  43. Trace.Warn("Custom Trace","Array count is null!");
  44. </pre></div>
  45.  
  46. <p>
  47. When Tracing is disabled (i.e. Trace="false" on the page directive, or not present), these statements will not execute and no trace output
  48. will appear in the client browser.  This makes it possible to keep debugging statements in production code and enable them conditionally
  49. at a later time. 
  50.  
  51. <p>
  52. Often you will need to execute additional code to construct the statements to pass to the Trace.Write or Trace.Warn methods, where this 
  53. code should only execute if tracing is enabled for the page.  To support this, the Page exposes a boolean property, 
  54. <b>Trace.IsEnabled</b>, which returns true only if tracing is enabled for the page.  You should check this property first to guarantee your 
  55. debugging code will only execute when tracing is on.
  56.  
  57. <div class="code"><pre>
  58. if (Trace.IsEnabled)
  59. {
  60.     for (int i=0; i<ds.Tables["Categories"].Rows.Count; i++)
  61.     {
  62.         Trace.Write("ProductCategory",ds.Tables["Categories"].Rows[i][0].ToString());
  63.     }
  64. }
  65. </pre></div>
  66.  
  67. <p>
  68. The following example shows the use of Trace.Write and Trace.Warn to output debugging statements.  Also note the use of the Trace.IsEnabled
  69. property to conditionally execute extra debugging code.  In this example, we have sorted the Trace information by category.
  70. <p>
  71.  
  72. <Acme:SourceRef 
  73.   RunSample="/quickstart/aspplus/samples/trace/trace2.aspx" 
  74.   ViewSource="/quickstart/aspplus/samples/trace/trace2.src"
  75.   Icon="/quickstart/aspplus/images/pagetrace2.gif"
  76.   Caption="Trace2.aspx"
  77.   runat="server" />
  78.  
  79. <p>
  80. ASP+ also provides a way to enable Tracing for the entire application (not just a single page).  To read more about application-level 
  81. tracing, click <a href="tracelogapp.aspx">here</a>.
  82.  
  83. <h4>Section Summary</h4>
  84. <ol>
  85. <li>Page-level tracing is enabled using a Trace="true" attribute on the top-level Page directive.
  86. <li>Page-level tracing allows developers to write debugging statements as part of a page's client output.  Trace statements are output using the Trace.Write and Trace.Warn methods, passing a category and message for each statement.
  87. <li>Debugging code may be conditionally executed depending on whether Trace is enabled for the page.  Use the Trace.IsEnabled property of the Page to determine whether tracing is enabled.
  88. </ol>
  89.  
  90.  
  91. <!-- #include virtual="/quickstart/aspplus/include/footer.inc" -->