TraceContextRecord.Message 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得使用者定義的追蹤訊息。
public:
property System::String ^ Message { System::String ^ get(); };
public string Message { get; }
member this.Message : string
Public ReadOnly Property Message As String
屬性值
字串,表示追蹤記錄的訊息。
範例
下列程式代碼範例示範如何存取 Message 的 TraceContextRecord屬性,並將它列印至 Response
數據流。
<%@ 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);
try {
throw new ArgumentException("Trace Test");
}
catch (InvalidOperationException ioe) {
// You can write an error trace message using the Write method.
Trace.Write("Exception Handling", "Exception: Page_Load.", ioe);
}
catch (ArgumentException ae) {
// You can write a warning trace message using the Warn method.
Trace.Warn("Exception Handling", "Warning: Page_Load.", ae);
}
}
// 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;
if (r.IsWarning) {
Response.Write(String.Format("warning message: {0} <BR>", r.Message));
}
else {
Response.Write(String.Format("error 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
Try
Dim ae As New ArgumentException("Trace Test")
Throw ae
catch ioe As InvalidOperationException
' You can write an error trace message using the Write method.
Trace.Write("Exception Handling", "Exception: Page_Load.", ioe)
Catch ae As ArgumentException
' You can write a warning trace message using the Warn method.
Trace.Warn("Exception Handling", "Warning: Page_Load.", ae)
End Try
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)
If r.IsWarning Then
Response.Write(String.Format("warning message: {0} <BR>", r.Message))
Else
Response.Write(String.Format("error message: {0} <BR>", r.Message))
End If
Next
End Sub ' OnTraceFinished
</script>
備註
訊息可以是任何字串,可用來撰寫詳細的追蹤資訊。 它會對應至傳遞至 和 TraceContext.Warn 方法的TraceContext.Write訊息參數。 此資訊可以是運行時間值、訊息來引導您,並引導您完成程序執行或其他診斷數據。