TraceContext.Write 메서드

정의

추적 로그에 추적 정보를 기록합니다.

오버로드

Write(String)

추적 로그에 추적 메시지를 기록합니다.

Write(String, String)

추적 로그에 메시지와 사용자 정의 범주를 포함한 추적 정보를 기록합니다.

Write(String, String, Exception)

추적 로그에 사용자 정의 범주, 추적 메시지 및 오류 정보를 비롯한 추적 정보를 기록합니다.

Write(String)

추적 로그에 추적 메시지를 기록합니다.

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

매개 변수

message
String

로그에 기록할 추적 메시지입니다.

설명

때마다를 Write 메서드가 호출 되는 TraceContext 추적 메시지에 추가 됩니다는 TraceRecords 메시지를 처리 하는 경우에 액세스할 수 있는 컬렉션은 TraceFinished 이벤트. 메시지와 함께 추가 됩니다 해당 IsWarning 속성으로 설정 false 및 해당 ErrorInfo 속성이 설정 null합니다.

추가 정보

적용 대상

Write(String, String)

추적 로그에 메시지와 사용자 정의 범주를 포함한 추적 정보를 기록합니다.

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

매개 변수

category
String

메시지를 받는 추적 범주입니다.

message
String

로그에 기록할 추적 메시지입니다.

예제

다음 코드 예제를 호출 하는 방법에 설명 합니다 Write 메서드를 추적 로그에 오류 추적 메시지를 씁니다. 이 예제에서는 대리자 추적 메시지를 통해 반복 하 고 HTML 테이블을; 형식으로 기록 그러나 데이터베이스를 프로 파일링 도구 소비자 동일한 정보를 작성할 수 있습니다.

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

설명

때마다를 Write 메서드가 호출 되는 TraceContext 추적 메시지에 추가 됩니다는 TraceRecords 메시지를 처리 하는 경우에 액세스할 수 있는 컬렉션은 TraceFinished 이벤트. 메시지와 함께 추가 됩니다 해당 IsWarning 속성으로 설정 false 및 해당 ErrorInfo 속성이 설정 null합니다.

추가 정보

적용 대상

Write(String, String, Exception)

추적 로그에 사용자 정의 범주, 추적 메시지 및 오류 정보를 비롯한 추적 정보를 기록합니다.

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

매개 변수

category
String

메시지를 받는 추적 범주입니다.

message
String

로그에 기록할 추적 메시지입니다.

errorInfo
Exception

오류에 대한 정보가 들어 있는 Exception입니다.

예제

다음 코드 예제를 호출 하는 방법에 설명 합니다 Write 메서드를 추적 로그에 오류 추적 메시지를 씁니다. 이 예제에서는 서로 다른 예외는 오류 및 경고로 추적 됩니다. 페이지가 throw 하는 경우는 ArgumentException를 사용 하 여 경고 메시지를 기록 합니다 Warn 메서드. 페이지가 throw 하는 경우는 InvalidOperationException를 사용 하 여 오류 메시지를 기록 합니다 Write 메서드.

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

설명

때마다를 Write 메서드가 호출 되는 TraceContext 추적 메시지에 추가 됩니다는 TraceRecords 메시지를 처리 하는 경우에 액세스할 수 있는 컬렉션은 TraceFinished 이벤트. 메시지와 함께 추가 됩니다 해당 IsWarning 속성으로 설정 false, 및 ErrorInfo 전달한 개체 속성을 errorInfo 매개 변수입니다.

추가 정보

적용 대상