Provides a listener that directs Trace messages to ASP.NET Web page outputs.
Namespace:
System.Web
Assembly:
System.Web (in System.Web.dll)
Visual Basic (Declaration)
<AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
<HostProtectionAttribute(SecurityAction.LinkDemand, Synchronization := True)> _
<AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
Public Class WebPageTraceListener _
Inherits TraceListener
Dim instance As WebPageTraceListener
[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[HostProtectionAttribute(SecurityAction.LinkDemand, Synchronization = true)]
[AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public class WebPageTraceListener : TraceListener
[AspNetHostingPermissionAttribute(SecurityAction::LinkDemand, Level = AspNetHostingPermissionLevel::Minimal)]
[HostProtectionAttribute(SecurityAction::LinkDemand, Synchronization = true)]
[AspNetHostingPermissionAttribute(SecurityAction::InheritanceDemand, Level = AspNetHostingPermissionLevel::Minimal)]
public ref class WebPageTraceListener : public TraceListener
public class WebPageTraceListener extends TraceListener
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 >
<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>
<%@ 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 >
<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..::.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 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
.NET Framework
Supported in: 3.5, 3.0, 2.0
Reference
Other Resources