.NET Framework Class Library
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)
Syntax
<[%$TOPIC/040095wf_en-us_VS_110_3_0_0_0_0%]([%$TOPIC/040095wf_en-us_VS_110_3_0_0_0_1%].LinkDemand, Synchronization := True)> _
Public Class WebPageTraceListener _
	Inherits [%$TOPIC/040095wf_en-us_VS_110_3_0_0_0_2%]
[[%$TOPIC/040095wf_en-us_VS_110_3_0_1_0_0%]([%$TOPIC/040095wf_en-us_VS_110_3_0_1_0_1%].LinkDemand, Synchronization = true)]
public class WebPageTraceListener : [%$TOPIC/040095wf_en-us_VS_110_3_0_1_0_2%]
[[%$TOPIC/040095wf_en-us_VS_110_3_0_2_0_0%]([%$TOPIC/040095wf_en-us_VS_110_3_0_2_0_1%]::LinkDemand, Synchronization = true)]
public ref class WebPageTraceListener : public [%$TOPIC/040095wf_en-us_VS_110_3_0_2_0_2%]
[<[%$TOPIC/040095wf_en-us_VS_110_3_0_3_0_0%]([%$TOPIC/040095wf_en-us_VS_110_3_0_3_0_1%].LinkDemand, Synchronization = true)>]
type WebPageTraceListener =  
    class 
        inherit [%$TOPIC/040095wf_en-us_VS_110_3_0_3_0_2%] 
    end

The WebPageTraceListener type exposes the following members.

Constructors
  NameDescription
Public method WebPageTraceListenerInitializes a new instance of the WebPageTraceListener class.
Top
Properties
  NameDescription
Public property AttributesGets the custom trace listener attributes defined in the application configuration file. (Inherited from TraceListener.)
Public property FilterGets and sets the trace filter for the trace listener. (Inherited from TraceListener.)
Public property IndentLevelGets or sets the indent level. (Inherited from TraceListener.)
Public property IndentSizeGets or sets the number of spaces in an indent. (Inherited from TraceListener.)
Public property IsThreadSafeGets a value indicating whether the trace listener is thread safe. (Inherited from TraceListener.)
Public property NameGets or sets a name for this TraceListener. (Inherited from TraceListener.)
Protected property NeedIndentGets or sets a value indicating whether to indent the output. (Inherited from TraceListener.)
Public property TraceOutputOptionsGets or sets the trace output options. (Inherited from TraceListener.)
Top
Methods
  NameDescription
Public method CloseWhen overridden in a derived class, closes the output stream so it no longer receives tracing or debugging output. (Inherited from TraceListener.)
Public method CreateObjRefCreates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object. (Inherited from MarshalByRefObject.)
Public method DisposeReleases all resources used by the TraceListener. (Inherited from TraceListener.)
Protected method Dispose(Boolean)Releases the unmanaged resources used by the TraceListener and optionally releases the managed resources. (Inherited from TraceListener.)
Public method Equals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Public method Fail(String)Emits an error message to the listener you create when you implement the TraceListener class. (Inherited from TraceListener.)
Public method Fail(String, String)Emits an error message and a detailed error message to the listener you create when you implement the TraceListener class. (Inherited from TraceListener.)
Protected method FinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method FlushWhen overridden in a derived class, flushes the output buffer. (Inherited from TraceListener.)
Public method GetHashCodeServes as the default hash function. (Inherited from Object.)
Public method GetLifetimeServiceRetrieves the current lifetime service object that controls the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Protected method GetSupportedAttributesGets the custom attributes supported by the trace listener. (Inherited from TraceListener.)
Public method GetTypeGets the Type of the current instance. (Inherited from Object.)
Public method InitializeLifetimeServiceObtains a lifetime service object to control the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Protected method MemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Protected method MemberwiseClone(Boolean)Creates a shallow copy of the current MarshalByRefObject object. (Inherited from MarshalByRefObject.)
Public method ToStringReturns a string that represents the current object. (Inherited from Object.)
Public method TraceData(TraceEventCache, String, TraceEventType, Int32, Object)Writes trace information, a data object and event information to the listener specific output. (Inherited from TraceListener.)
Public method TraceData(TraceEventCache, String, TraceEventType, Int32, Object)Writes trace information, an array of data objects and event information to the listener specific output. (Inherited from TraceListener.)
Public method TraceEvent(TraceEventCache, String, TraceEventType, Int32)Writes trace and event information to the listener specific output. (Inherited from TraceListener.)
Public method TraceEvent(TraceEventCache, String, TraceEventType, Int32, String)Writes an event message to a Web page or to the ASP.NET trace viewer using the specified system and event data. (Overrides TraceListenerTraceEvent(TraceEventCache, String, TraceEventType, Int32, String).)
Public method TraceEvent(TraceEventCache, String, TraceEventType, Int32, String, Object)Writes a localized event message to a Web page or to the ASP.NET trace viewer using the specified system and event data. (Overrides TraceListenerTraceEvent(TraceEventCache, String, TraceEventType, Int32, String, Object).)
Public method TraceTransferWrites trace information, a message, a related activity identity and event information to the listener specific output. (Inherited from TraceListener.)
Public method Write(Object)Writes the value of the object's ToString method to the listener you create when you implement the TraceListener class. (Inherited from TraceListener.)
Public method Write(String)Writes a message to a Web page or to the ASP.NET trace viewer. (Overrides TraceListenerWrite(String).)
Public method Write(Object, String)Writes a category name and the value of the object's ToString method to the listener you create when you implement the TraceListener class. (Inherited from TraceListener.)
Public method Write(String, String)Writes a category name and a message to a Web page or to the ASP.NET trace viewer. (Overrides TraceListenerWrite(String, String).)
Protected method WriteIndentWrites the indent to the listener you create when you implement this class, and resets the NeedIndent property to false. (Inherited from TraceListener.)
Public method WriteLine(Object)Writes the value of the object's ToString method to the listener you create when you implement the TraceListener class, followed by a line terminator. (Inherited from TraceListener.)
Public method WriteLine(String)Writes a message to a Web page or to the ASP.NET trace viewer. (Overrides TraceListenerWriteLine(String).)
Public method WriteLine(Object, String)Writes a category name and the value of the object's ToString method to the listener you create when you implement the TraceListener class, followed by a line terminator. (Inherited from TraceListener.)
Public method WriteLine(String, String)Writes a category name and a message to a Web page or to the ASP.NET trace viewer. (Overrides TraceListenerWriteLine(String, String).)
Top
Remarks
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.

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.

Examples

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>
<%@ 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>
Version Information

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0
Platforms

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

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