TraceContextRecord Class
Assembly: System.Web (in system.web.dll)
The TraceContextRecord object encapsulates the trace message, category, any associated Exception, and whether the trace record was written by the System.Web.TraceContext.Warn method.
Every call to the System.Web.TraceContext.Write and System.Web.TraceContext.Warn methods generates a TraceContextRecord object that is added to the TraceContextEventArgs.TraceRecords messages collection. You can access the collection of records by handling the TraceFinished event.
The following code example demonstrates how you can register a TraceContextEventHandler delegate to handle the TraceFinished event. In this example, the OnTraceFinished method accesses the collection of TraceContextRecord objects through the TraceRecords property, iterates through them, and writes them to the response stream.
<%@ Page language="VB" Trace="true" %> <script runat="server"> ' The Page_Load method. Private Sub Page_Load(sender As Object, e As EventArgs) ' Register a handler for the TraceFinished event. AddHandler Trace.TraceFinished, AddressOf OnTraceFinished ' Write a trace message. Trace.Write("Web Forms Infrastructure Methods", "USERMESSAGE: Page_Load complete.") End Sub ' Page_Load ' A TraceContextEventHandler for the TraceFinished event. Private Sub OnTraceFinished(sender As Object, e As TraceContextEventArgs) Dim r As TraceContextRecord Dim o As Object ' Iterate through the collection of trace records and write ' them to the response stream. For Each o In e.TraceRecords r = CType(o, TraceContextRecord) Response.Write(String.Format("trace message: {0} <BR>", r.Message)) Next End Sub ' OnTraceFinished </script>
- SecurityPermission for operating in a hosted environment. Demand value: LinkDemand; Permission value: Minimal.