TraceContextRecord.Category Propriedade

Definição

Obtém a categoria definida pelo utilizador para o registo de rastreio.

public:
 property System::String ^ Category { System::String ^ get(); };
public string Category { get; }
member this.Category : string
Public ReadOnly Property Category As String

Valor de Propriedade

Uma cadeia que representa uma categoria para o registo de traço.

Exemplos

O exemplo de código seguinte demonstra como aceder à Category propriedade de um TraceContextRecord, e imprimi-la juntamente com a sua mensagem de rastreio associada para o Response fluxo.

<%@ 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>

Observações

A categoria é usada para organizar melhor as mensagens de traço em grupos reconhecíveis, mas pode ser qualquer string. A TraceContext classe utiliza String.Empty como categoria padrão métodos que aceitam apenas um message parâmetro. A categoria padrão para ASP.NET, que escreve vários registos de rastreio quando o rastreio está ativado, é "aspx.page".

Aplica-se a

Ver também