다음을 통해 공유


TraceContext.Write 메서드

정의

추적 정보를 추적 로그에 씁니다.

오버로드

Name Description
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 속성이 ErrorInfo .로 설정된 상태로 추가됩니다null.false

추가 정보

적용 대상

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 속성이 ErrorInfo .로 설정된 상태로 추가됩니다null.false

추가 정보

적용 대상

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 오류 추적 메시지를 작성 하는 메서드를 호출 하는 방법을 보여 줍니다. 이 예제에서는 다른 예외가 오류 및 경고로 추적됩니다. 페이지가 ArgumentExceptionthrow되면 메서드를 사용하여 Warn 경고 메시지를 씁니다. 페이지가 InvalidOperationExceptionthrow되면 메서드를 사용하여 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 .

추가 정보

적용 대상