WebPageTraceListener Class
Assembly: System.Web (in system.web.dll)
Note: |
|---|
| The HostProtectionAttribute attribute applied to this class has the following Resources property value: Synchronization. The HostProtectionAttribute does not affect desktop applications (which are typically started by double-clicking an icon, typing a command, or entering a URL in a browser). For more information, see the HostProtectionAttribute class or SQL Server Programming and Host Protection Attributes. |
The WebPageTraceListener class forwards trace messages that are written to the Trace log to ASP.NET Web page output channels. You can enable trace forwarding by adding a WebPageTraceListener object to your Web.config file as a listener in the trace Element (ASP.NET Settings Schema) subsection of the <system.diagnostics> Element section. You can also add a WebPageTraceListener to the listeners collection programmatically. Commonly, this is done by adding a WebPageTraceListener to the collection during application startup, using the Application_Start method in the Global.asax file.
| Topic | Location |
|---|---|
| Walkthrough: Integrating ASP.NET Tracing with System.Diagnostics Tracing | Building ASP .NET Web Applications |
| Walkthrough: Integrating ASP.NET Tracing with System.Diagnostics Tracing | Building ASP .NET Web Applications |
The following code example demonstrates how to route Trace messages to Web form output. The code example shows a typical Web form containing a BulletedList and AccessDataSource control. Tracing is enabled on the Web form and trace output is appended to the Web form when it is rendered. You can examine the trace messages in the Trace Information table of the trace output. If you have enabled the WebPageTraceListener correctly in your configuration file, you see both trace messages with the category "Trace Test". However, if you have not enabled the WebPageTraceListener, you see only the trace message that is written to the TraceContext object.
<%@ Page language="C#" trace="true" %> <script runat="server"> private void page_load(object sender, EventArgs e) { Trace.Write("Trace Test","This message is written with the TraceContext object."); System.Diagnostics.Trace.WriteLine("This message is forwarded to the TraceContext from System.Diagnostics using the WebPageTraceListener."); } </script> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>ASP.NET Example</title> </head> <body> <form id="Form1" runat="server"> <asp:GridView id="GridView1" runat="server" datasourceid="AccessDataSource1"/> <asp:AccessDataSource id="AccessDataSource1" runat="server" datafile="Northwind.mdb" selectcommand="SELECT * FROM employees"/> </form> </body> </html>
System.MarshalByRefObject
System.Diagnostics.TraceListener
System.Web.WebPageTraceListener
Note: