WebPageTraceListener Class
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Provides a listener that directs Trace messages to ASP.NET Web page outputs.
public ref class WebPageTraceListener : System::Diagnostics::TraceListener
public class WebPageTraceListener : System.Diagnostics.TraceListener
type WebPageTraceListener = class
inherit TraceListener
Public Class WebPageTraceListener
Inherits TraceListener
- Inheritance
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>
Remarks
Note
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> 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.
Constructors
WebPageTraceListener() |
Initializes a new instance of the WebPageTraceListener class. |
Properties
Attributes |
Gets the custom trace listener attributes defined in the application configuration file. (Inherited from TraceListener) |
Filter |
Gets or sets the trace filter for the trace listener. (Inherited from TraceListener) |
IndentLevel |
Gets or sets the indent level. (Inherited from TraceListener) |
IndentSize |
Gets or sets the number of spaces in an indent. (Inherited from TraceListener) |
IsThreadSafe |
Gets a value indicating whether the trace listener is thread safe. (Inherited from TraceListener) |
Name |
Gets or sets a name for this TraceListener. (Inherited from TraceListener) |
NeedIndent |
Gets or sets a value indicating whether to indent the output. (Inherited from TraceListener) |
TraceOutputOptions |
Gets or sets the trace output options. (Inherited from TraceListener) |
Methods
Close() |
When overridden in a derived class, closes the output stream so it no longer receives tracing or debugging output. (Inherited from TraceListener) |
CreateObjRef(Type) |
Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object. (Inherited from MarshalByRefObject) |
Dispose() |
Releases all resources used by the TraceListener. (Inherited from TraceListener) |
Dispose(Boolean) |
Releases the unmanaged resources used by the TraceListener and optionally releases the managed resources. (Inherited from TraceListener) |
Equals(Object) |
Determines whether the specified object is equal to the current object. (Inherited from Object) |
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) |
Fail(String) |
Emits an error message to the listener you create when you implement the TraceListener class. (Inherited from TraceListener) |
Flush() |
When overridden in a derived class, flushes the output buffer. (Inherited from TraceListener) |
GetHashCode() |
Serves as the default hash function. (Inherited from Object) |
GetLifetimeService() |
Obsolete.
Retrieves the current lifetime service object that controls the lifetime policy for this instance. (Inherited from MarshalByRefObject) |
GetSupportedAttributes() |
Gets the custom attributes supported by the trace listener. (Inherited from TraceListener) |
GetType() |
Gets the Type of the current instance. (Inherited from Object) |
InitializeLifetimeService() |
Obsolete.
Obtains a lifetime service object to control the lifetime policy for this instance. (Inherited from MarshalByRefObject) |
MemberwiseClone() |
Creates a shallow copy of the current Object. (Inherited from Object) |
MemberwiseClone(Boolean) |
Creates a shallow copy of the current MarshalByRefObject object. (Inherited from MarshalByRefObject) |
ToString() |
Returns a string that represents the current object. (Inherited from Object) |
TraceData(TraceEventCache, String, TraceEventType, Int32, Object) |
Writes trace information, a data object and event information to the listener specific output. (Inherited from TraceListener) |
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) |
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. |
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. |
TraceEvent(TraceEventCache, String, TraceEventType, Int32) |
Writes trace and event information to the listener specific output. (Inherited from TraceListener) |
TraceTransfer(TraceEventCache, String, Int32, String, Guid) |
Writes trace information, a message, a related activity identity and event information to the listener specific output. (Inherited from TraceListener) |
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) |
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) |
Write(String, String) |
Writes a category name and a message to a Web page or to the ASP.NET trace viewer. |
Write(String) |
Writes a message to a Web page or to the ASP.NET trace viewer. |
WriteIndent() |
Writes the indent to the listener you create when you implement this class, and resets the NeedIndent property to |
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) |
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) |
WriteLine(String, String) |
Writes a category name and a message to a Web page or to the ASP.NET trace viewer. |
WriteLine(String) |
Writes a message to a Web page or to the ASP.NET trace viewer. |