共用方式為


TraceContext.TraceFinished 事件

定義

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

適用於

另請參閱