TraceContextRecord.Category 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取跟踪记录的用户定义的类别。
public:
property System::String ^ Category { System::String ^ get(); };
public string Category { get; }
member this.Category : string
Public ReadOnly Property Category As String
属性值
表示跟踪记录的类别的字符串。
示例
下面的代码示例演示如何访问 Category 的 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);
// 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.
Response.Write("<table>");
foreach(object o in e.TraceRecords)
{
r = (TraceContextRecord)o;
Response.Write(String.Format("<tr><td>{0}</td><td>{1}</td></tr>", r.Message, r.Category));
}
Response.Write("</table>");
}
</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.
Response.Write("<table>")
For Each o In e.TraceRecords
r = CType(o, TraceContextRecord)
Response.Write(String.Format("<tr><td>{0}</td><td>{1}</td></tr>", r.Message, r.Category))
Next
Response.Write("</table>")
End Sub ' OnTraceFinished
</script>
注解
类别用于更好地将跟踪消息组织到可识别的组中,但可以是任何字符串。 类 TraceContext 使用 String.Empty 作为仅 message
采用参数的方法的默认类别。 ASP.NET 的默认类别(启用跟踪时写入多个跟踪记录)为“aspx.page”。