TraceContext.Warn Método

Definição

Grava informações de rastreamento no log de rastreamento.Writes trace information to the trace log. Ao contrário de Write(String), todos os avisos aparecem no log de como texto vermelho.Unlike Write(String), all warnings appear in the log as red text.

Sobrecargas

Warn(String)

Grava uma mensagem de rastreamento no log de rastreamento.Writes a trace message to the trace log. Todos os avisos aparecem no log como texto em vermelho.All warnings appear in the log as red text.

Warn(String, String)

Grava informações no log de rastreamento, incluindo quaisquer categorias definidas pelo usuário e mensagens de rastreamento.Writes trace information to the trace log, including any user-defined categories and trace messages. Todos os avisos aparecem no log como texto em vermelho.All warnings appear in the log as red text.

Warn(String, String, Exception)

Grava informações no log de rastreamento, incluindo quaisquer categorias definidas pelo usuário, mensagens de rastreamento e informações de erro.Writes trace information to the trace log, including any user-defined categories, trace messages, and error information. Todos os avisos aparecem no log como texto em vermelho.All warnings appear in the log as red text.

Warn(String)

Grava uma mensagem de rastreamento no log de rastreamento.Writes a trace message to the trace log. Todos os avisos aparecem no log como texto em vermelho.All warnings appear in the log as red text.

public:
 void Warn(System::String ^ message);
public void Warn (string message);
member this.Warn : string -> unit
Public Sub Warn (message As String)

Parâmetros

message
String

A mensagem de rastreamento a ser gravada no log.The trace message to write to the log.

Comentários

Sempre que o Warn método é chamado, uma TraceContext mensagem de rastreamento é adicionada à TraceRecords coleção de mensagens, que é acessível quando você manipula o TraceFinished evento.Every time the Warn method is called, a TraceContext trace message is added to the TraceRecords messages collection, which is accessible when you handle the TraceFinished event. A mensagem é adicionada com sua IsWarning propriedade definida como true e sua ErrorInfo propriedade definida como null .The message is added with its IsWarning property set to true and its ErrorInfo property set to null.

Aplica-se a

Warn(String, String)

Grava informações no log de rastreamento, incluindo quaisquer categorias definidas pelo usuário e mensagens de rastreamento.Writes trace information to the trace log, including any user-defined categories and trace messages. Todos os avisos aparecem no log como texto em vermelho.All warnings appear in the log as red text.

public:
 void Warn(System::String ^ category, System::String ^ message);
public void Warn (string category, string message);
member this.Warn : string * string -> unit
Public Sub Warn (category As String, message As String)

Parâmetros

category
String

A categoria de rastreamento que recebe a mensagem.The trace category that receives the message.

message
String

A mensagem de rastreamento a ser gravada no log.The trace message to write to the log.

Comentários

Sempre que o Warn método é chamado, uma TraceContext mensagem de rastreamento é adicionada à TraceRecords coleção de mensagens, que é acessível quando você manipula o TraceFinished evento.Every time the Warn method is called, a TraceContext trace message is added to the TraceRecords messages collection, which is accessible when you handle the TraceFinished event. A mensagem é adicionada com sua IsWarning propriedade definida como true e sua ErrorInfo propriedade definida como null .The message is added with its IsWarning property set to true and its ErrorInfo property set to null.

Aplica-se a

Warn(String, String, Exception)

Grava informações no log de rastreamento, incluindo quaisquer categorias definidas pelo usuário, mensagens de rastreamento e informações de erro.Writes trace information to the trace log, including any user-defined categories, trace messages, and error information. Todos os avisos aparecem no log como texto em vermelho.All warnings appear in the log as red text.

public:
 void Warn(System::String ^ category, System::String ^ message, Exception ^ errorInfo);
public void Warn (string category, string message, Exception errorInfo);
member this.Warn : string * string * Exception -> unit
Public Sub Warn (category As String, message As String, errorInfo As Exception)

Parâmetros

category
String

A categoria de rastreamento que recebe a mensagem.The trace category that receives the message.

message
String

A mensagem de rastreamento a ser gravada no log.The trace message to write to the log.

errorInfo
Exception

Um Exception que contém informações sobre o erro.An Exception that contains information about the error.

Exemplos

O exemplo de código a seguir demonstra como chamar o Write método para gravar uma mensagem de rastreamento de erro no log de rastreamento.The following code example demonstrates how to call the Write method to write an error trace message to the trace log. Neste exemplo, diferentes exceções são rastreadas como erros e avisos.In this example, different exceptions are traced as errors and warnings. Quando a página gera uma ArgumentException , ela grava uma mensagem de aviso usando o Warn método.When the page throws an ArgumentException, it writes a warning message using the Warn method. Quando a página gera um InvalidOperationException , ele grava uma mensagem de erro usando o Write método.When the page throws an InvalidOperationException, it writes an error message using the Write method.

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

Comentários

Sempre que o Warn método é chamado, uma TraceContext mensagem de rastreamento é adicionada à TraceRecords coleção de mensagens, que é acessível quando você manipula o TraceFinished evento.Every time the Warn method is called, a TraceContext trace message is added to the TraceRecords messages collection, which is accessible when you handle the TraceFinished event. A mensagem é adicionada com sua IsWarning propriedade definida como true e a ErrorInfo propriedade é definida como o objeto passado pelo errorInfo parâmetro.The message is added with its IsWarning property set to true, and the ErrorInfo property is set to the object passed by the errorInfo parameter.

Confira também

Aplica-se a