Export (0) Print
Expand All

WebPageTraceListener Class

Provides a listener that directs Trace messages to ASP.NET Web page outputs.

Namespace: System.Web
Assembly: System.Web (in system.web.dll)

'Declaration
Public Class WebPageTraceListener
	Inherits TraceListener
'Usage
Dim instance As WebPageTraceListener

public class WebPageTraceListener extends TraceListener
public class WebPageTraceListener extends TraceListener
Not applicable.

NoteNote:

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.

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="VB" trace="true" %>

<script runat="server">
Private Sub Page_Load(sender As Object, e As EventArgs)
    
    Trace.Write("Trace Test","This message is written with the System.Web.TraceContext object.")

    System.Diagnostics.Trace.Write("Trace Test", "This message is forwarded to the TraceContext from System.Diagnostics using the WebPageTraceListener.")

End Sub ' Page_Load
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <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.Object
   System.MarshalByRefObject
     System.Diagnostics.TraceListener
      System.Web.WebPageTraceListener

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

Community Additions

ADD
Show:
© 2014 Microsoft