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)

Inheritance Hierarchy
SystemObject
   SystemMarshalByRefObject
     System.DiagnosticsTraceListener
      System.WebWebPageTraceListener

Syntax
[HostProtectionAttribute(SecurityAction.LinkDemand, Synchronization = true)]
public class WebPageTraceListener : TraceListener
[HostProtectionAttribute(SecurityAction::LinkDemand, Synchronization = true)]
public ref class WebPageTraceListener : TraceListener
[<HostProtectionAttribute(SecurityAction.LinkDemand, Synchronization = true)>]
type WebPageTraceListener = 
    class
        inherit TraceListener
    end
<HostProtectionAttribute(SecurityAction.LinkDemand, Synchronization := True)>
Public Class WebPageTraceListener
	Inherits TraceListener
Constructors
NameDescription
System_CAPS_pubmethod WebPageTraceListener

Initializes a new instance of the WebPageTraceListener class.

Properties
NameDescription
System_CAPS_pubproperty

Gets the custom trace listener attributes defined in the application configuration file.(Inherited from TraceListener.)

System_CAPS_pubproperty

Gets and sets the trace filter for the trace listener.(Inherited from TraceListener.)

System_CAPS_pubproperty

Gets or sets the indent level.(Inherited from TraceListener.)

System_CAPS_pubproperty

Gets or sets the number of spaces in an indent.(Inherited from TraceListener.)

System_CAPS_pubproperty

Gets a value indicating whether the trace listener is thread safe. (Inherited from TraceListener.)

System_CAPS_pubproperty

Gets or sets a name for this TraceListener.(Inherited from TraceListener.)

System_CAPS_protproperty

Gets or sets a value indicating whether to indent the output.(Inherited from TraceListener.)

System_CAPS_pubproperty

Gets or sets the trace output options.(Inherited from TraceListener.)

Methods
NameDescription
System_CAPS_pubmethod Close

When overridden in a derived class, closes the output stream so it no longer receives tracing or debugging output.(Inherited from TraceListener.)

System_CAPS_pubmethod CreateObjRef

Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.(Inherited from MarshalByRefObject.)

System_CAPS_pubmethod Dispose

Releases all resources used by the TraceListener.(Inherited from TraceListener.)

System_CAPS_protmethod Dispose

Releases the unmanaged resources used by the TraceListener and optionally releases the managed resources.(Inherited from TraceListener.)

System_CAPS_pubmethod Equals

Determines whether the specified object is equal to the current object.(Inherited from Object.)

System_CAPS_pubmethod Fail

Emits an error message to the listener you create when you implement the TraceListener class.(Inherited from TraceListener.)

System_CAPS_pubmethod Fail

Emits an error message and a detailed error message to the listener you create when you implement the TraceListener class.(Inherited from TraceListener.)

System_CAPS_protmethod Finalize

Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.)

System_CAPS_pubmethod Flush

When overridden in a derived class, flushes the output buffer.(Inherited from TraceListener.)

System_CAPS_pubmethod GetHashCode

Serves as the default hash function. (Inherited from Object.)

System_CAPS_pubmethod GetLifetimeService

Retrieves the current lifetime service object that controls the lifetime policy for this instance.(Inherited from MarshalByRefObject.)

System_CAPS_protmethod GetSupportedAttributes

Gets the custom attributes supported by the trace listener.(Inherited from TraceListener.)

System_CAPS_pubmethod GetType

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_pubmethod InitializeLifetimeService

Obtains a lifetime service object to control the lifetime policy for this instance.(Inherited from MarshalByRefObject.)

System_CAPS_protmethod MemberwiseClone

Creates a shallow copy of the current Object.(Inherited from Object.)

System_CAPS_protmethod MemberwiseClone

Creates a shallow copy of the current MarshalByRefObject object.(Inherited from MarshalByRefObject.)

System_CAPS_pubmethod ToString

Returns a string that represents the current object.(Inherited from Object.)

System_CAPS_pubmethod TraceData

Writes trace information, a data object and event information to the listener specific output.(Inherited from TraceListener.)

System_CAPS_pubmethod TraceData

Writes trace information, an array of data objects and event information to the listener specific output.(Inherited from TraceListener.)

System_CAPS_pubmethod TraceEvent

Writes trace and event information to the listener specific output.(Inherited from TraceListener.)

System_CAPS_pubmethod TraceEvent

Writes an event message to a Web page or to the ASP.NET trace viewer using the specified system and event data.(Overrides TraceListenerTraceEvent.)

System_CAPS_pubmethod TraceEvent

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.)

System_CAPS_pubmethod TraceTransfer

Writes trace information, a message, a related activity identity and event information to the listener specific output.(Inherited from TraceListener.)

System_CAPS_pubmethod Write

Writes the value of the object's ToString method to the listener you create when you implement the TraceListener class.(Inherited from TraceListener.)

System_CAPS_pubmethod Write

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.)

System_CAPS_pubmethod Write

Writes a message to a Web page or to the ASP.NET trace viewer.(Overrides TraceListenerWrite.)

System_CAPS_pubmethod Write

Writes a category name and a message to a Web page or to the ASP.NET trace viewer.(Overrides TraceListenerWrite.)

System_CAPS_protmethod WriteIndent

Writes the indent to the listener you create when you implement this class, and resets the property to false.(Inherited from TraceListener.)

System_CAPS_pubmethod WriteLine

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.)

System_CAPS_pubmethod WriteLine

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.)

System_CAPS_pubmethod WriteLine

Writes a message to a Web page or to the ASP.NET trace viewer.(Overrides TraceListenerWriteLine.)

System_CAPS_pubmethod WriteLine

Writes a category name and a message to a Web page or to the ASP.NET trace viewer.(Overrides TraceListenerWriteLine.)

Remarks
System_CAPS_noteNote

The HostProtectionAttribute attribute applied to this class has the following 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.

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="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>
<%@ 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>
Version Information
.NET Framework
Available since 2.0
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.

Return to top