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)

[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[HostProtectionAttribute(SecurityAction.LinkDemand, Synchronization = true)]
[AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public class WebPageTraceListener : TraceListener

NoteNote:

The HostProtectionAttribute attribute applied to this type or member 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.

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="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>

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

Community Additions

ADD
Show:
© 2014 Microsoft