Export (0) Print
Expand All
1 out of 1 rated this helpful - Rate this topic

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)
[HostProtectionAttribute(SecurityAction.LinkDemand, Synchronization = true)]
public class WebPageTraceListener : TraceListener

The WebPageTraceListener type exposes the following members.

  NameDescription
Public methodWebPageTraceListenerInitializes a new instance of the WebPageTraceListener class.
Top
  NameDescription
Public propertyAttributesGets the custom trace listener attributes defined in the application configuration file. (Inherited from TraceListener.)
Public propertyFilterGets and sets the trace filter for the trace listener. (Inherited from TraceListener.)
Public propertyIndentLevelGets or sets the indent level. (Inherited from TraceListener.)
Public propertyIndentSizeGets or sets the number of spaces in an indent. (Inherited from TraceListener.)
Public propertyIsThreadSafeGets a value indicating whether the trace listener is thread safe. (Inherited from TraceListener.)
Public propertyNameGets or sets a name for this TraceListener. (Inherited from TraceListener.)
Protected propertyNeedIndentGets or sets a value indicating whether to indent the output. (Inherited from TraceListener.)
Public propertyTraceOutputOptionsGets or sets the trace output options. (Inherited from TraceListener.)
Top
  NameDescription
Public methodCloseWhen overridden in a derived class, closes the output stream so it no longer receives tracing or debugging output. (Inherited from TraceListener.)
Public methodCreateObjRefCreates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object. (Inherited from MarshalByRefObject.)
Public methodDispose()Releases all resources used by the TraceListener. (Inherited from TraceListener.)
Protected methodDispose(Boolean)Releases the unmanaged resources used by the TraceListener and optionally releases the managed resources. (Inherited from TraceListener.)
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Public methodFail(String)Emits an error message to the listener you create when you implement the TraceListener class. (Inherited from TraceListener.)
Public methodFail(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 methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodFlushWhen overridden in a derived class, flushes the output buffer. (Inherited from TraceListener.)
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetLifetimeServiceRetrieves the current lifetime service object that controls the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Protected methodGetSupportedAttributesGets the custom attributes supported by the trace listener. (Inherited from TraceListener.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodInitializeLifetimeServiceObtains a lifetime service object to control the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Protected methodMemberwiseClone()Creates a shallow copy of the current Object. (Inherited from Object.)
Protected methodMemberwiseClone(Boolean)Creates a shallow copy of the current MarshalByRefObject object. (Inherited from MarshalByRefObject.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Public methodTraceData(TraceEventCache, String, TraceEventType, Int32, Object)Writes trace information, a data object and event information to the listener specific output. (Inherited from TraceListener.)
Public methodTraceData(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 methodTraceEvent(TraceEventCache, String, TraceEventType, Int32)Writes trace and event information to the listener specific output. (Inherited from TraceListener.)
Public methodTraceEvent(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 TraceListener.TraceEvent(TraceEventCache, String, TraceEventType, Int32, String).)
Public methodTraceEvent(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 TraceListener.TraceEvent(TraceEventCache, String, TraceEventType, Int32, String, Object[]).)
Public methodTraceTransferWrites trace information, a message, a related activity identity and event information to the listener specific output. (Inherited from TraceListener.)
Public methodWrite(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 methodWrite(String)Writes a message to a Web page or to the ASP.NET trace viewer. (Overrides TraceListener.Write(String).)
Public methodWrite(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 methodWrite(String, String)Writes a category name and a message to a Web page or to the ASP.NET trace viewer. (Overrides TraceListener.Write(String, String).)
Protected methodWriteIndentWrites the indent to the listener you create when you implement this class, and resets the NeedIndent property to false. (Inherited from TraceListener.)
Public methodWriteLine(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 methodWriteLine(String)Writes a message to a Web page or to the ASP.NET trace viewer. (Overrides TraceListener.WriteLine(String).)
Public methodWriteLine(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 methodWriteLine(String, String)Writes a category name and a message to a Web page or to the ASP.NET trace viewer. (Overrides TraceListener.WriteLine(String, String).)
Top
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.

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>

.NET Framework

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

Windows Phone 8.1, Windows Phone 8, 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.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.