TraceContextEventArgs.TraceRecords 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得與目前要求相關聯的 TraceContextRecord 訊息集合。
public:
property System::Collections::ICollection ^ TraceRecords { System::Collections::ICollection ^ get(); };
public System.Collections.ICollection TraceRecords { get; }
member this.TraceRecords : System.Collections.ICollection
Public ReadOnly Property TraceRecords As ICollection
屬性值
與目前要求相關聯的追蹤記錄集合。
範例
下列程式代碼範例示範如何註冊 TraceContextEventHandler 委派來處理 TraceFinished 事件。 在此範例中,方法會OnTraceFinished
透過 TraceRecords 屬性存取 物件的集合TraceContextRecord、逐一查看物件,並將其寫入響應數據流。
<%@ 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>
備註
對 和 TraceContext.Warn 方法的每個呼叫TraceContext.Write都會TraceContextRecord產生物件,該物件會新增至TraceRecords訊息集合。 方法呼叫會將 WarnIsWarning 屬性設定為 true
,而其他方法呼叫則會將其設定為 false
。
您可以逐一查看訊息, TraceRecords 並檢查具有特定類別或訊息的記錄,以及它們是否為警告。