TraceContext.TraceFinished 事件
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
由 TraceContext 对象引发,用于在收集完所有请求信息后公开跟踪消息。
public:
event System::Web::TraceContextEventHandler ^ TraceFinished;
public event System.Web.TraceContextEventHandler TraceFinished;
member this.TraceFinished : System.Web.TraceContextEventHandler
Public Custom Event TraceFinished As TraceContextEventHandler
事件类型
示例
下面的代码示例演示如何注册 以 TraceContextEventHandler 处理 TraceFinished 事件。 在此示例中,委托循环访问跟踪消息并将其写入响应流;但是,可以将相同的信息写入数据库或分析工具使用者。
<%@ Page language="c#" Trace="true" %>
<script runat="server">
void Page_Load(object sender, EventArgs e)
{
// Register a handler for the TraceFinished event.
Trace.TraceFinished += new
TraceContextEventHandler(this.OnTraceFinished);
// Write a trace message.
Trace.Write("Web Forms Infrastructure Methods", "USERMESSAGE: Page_Load complete.");
}
// A TraceContextEventHandler for the TraceFinished event.
void OnTraceFinished(object sender, TraceContextEventArgs e)
{
TraceContextRecord r = null;
// Iterate through the collection of trace records and write
// them to the response stream.
foreach(object o in e.TraceRecords)
{
r = (TraceContextRecord)o;
Response.Write(String.Format("trace message: {0} <BR>", r.Message));
}
}
</script>
<%@ 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>
注解
事件 TraceFinished 在 HTTP 请求处理阶段引发 EndRequest
。 它由 TraceContext 对象在收集所有请求信息后引发,以向已注册TraceContextEventHandler的委托公开消息集合TraceContextRecord。