Trace.WriteLineIf 메서드

정의

조건이 true있는 경우 추적에 대한 정보를 컬렉션의 Listeners 추적 수신기에 씁니다.

오버로드

Name Description
WriteLineIf(Boolean, Object, String)

조건이 ToString()있는 경우 범주 이름과 개체 메서드 값을 컬렉션의 Listeners 추적 수신기에 true 씁니다.

WriteLineIf(Boolean, Object)

조건이 ToString()있는 경우 개체 메서드의 값을 컬렉션의 Listeners 추적 수신기에 true 씁니다.

WriteLineIf(Boolean, String)

조건이 Listeners있는 경우 컬렉션의 추적 수신기에 true 메시지를 씁니다.

WriteLineIf(Boolean, String, String)

조건이 Listeners있는 경우 컬렉션의 추적 수신기에 true 범주 이름 및 메시지를 씁니다.

WriteLineIf(Boolean, Object, String)

조건이 ToString()있는 경우 범주 이름과 개체 메서드 값을 컬렉션의 Listeners 추적 수신기에 true 씁니다.

public:
 static void WriteLineIf(bool condition, System::Object ^ value, System::String ^ category);
[System.Diagnostics.Conditional("TRACE")]
public static void WriteLineIf(bool condition, object value, string category);
[<System.Diagnostics.Conditional("TRACE")>]
static member WriteLineIf : bool * obj * string -> unit
Public Shared Sub WriteLineIf (condition As Boolean, value As Object, category As String)

매개 변수

condition
Boolean

true메시지를 작성하려면 이고, 그렇지 않으면 . false

value
Object

Object 이름이 .로 전송되는 이름Listeners입니다.

category
String

출력을 구성하는 데 사용되는 범주 이름입니다.

특성

예제

다음 예제에서는 명명TraceSwitch된 .generalSwitch 이 스위치는 코드 샘플 외부에서 설정됩니다.

스위치가 더 높은 값으로 TraceLevelError 설정된 경우 예제에서는 첫 번째 오류 메시지를 Listeners출력합니다. 컬렉션에 수신기 Listeners 를 추가하는 방법에 대한 자세한 내용은 클래스를 TraceListenerCollection 참조하세요.

그런 다음, 설정된 TraceLevel경우 Verbose 예제에서는 첫 번째 메시지와 동일한 줄에 두 번째 오류 메시지를 출력합니다. 두 번째 메시지 뒤에 줄 종결자가 잇습니다.

// Class-level declaration.
 // Create a TraceSwitch.
 static TraceSwitch generalSwitch = new TraceSwitch("General", "Entire Application");

 static public void MyErrorMethod(Object myObject, string category) {
    // Write the message if the TraceSwitch level is set to Error or higher.
    Trace.WriteIf(generalSwitch.TraceError, "Invalid object for category. ");

    // Write a second message if the TraceSwitch level is set to Verbose.
    Trace.WriteLineIf(generalSwitch.TraceVerbose, myObject, category);
 }
' Class-level declaration.
' Create a TraceSwitch.
Private Shared generalSwitch As New TraceSwitch("General", "Entire Application")

Public Shared Sub MyErrorMethod(myObject As Object, category As String)
    ' Write the message if the TraceSwitch level is set to Error or higher.
    Trace.WriteIf(generalSwitch.TraceError, "Invalid object for category. ")
    
    ' Write a second message if the TraceSwitch level is set to Verbose.
    Trace.WriteLineIf(generalSwitch.TraceVerbose, myObject, category)
End Sub

설명

기본적으로 출력은 .의 DefaultTraceListener인스턴스에 기록됩니다.

매개 변수를 category 사용하여 출력 메시지를 그룹화할 수 있습니다.

이 메서드는 WriteLine 추적 수신기의 메서드를 호출합니다.

상속자 참고

문을 사용하는 WriteLineIf(Boolean, String) 대신 문을 사용하여 If...Then 애플리케이션 계측의 성능 저하를 최소화할 수 있습니다. 다음 두 코드 예제에서는 동일한 디버깅 메시지를 보냅니다. 그러나 첫 번째 예제는 추적이 꺼져 있을 때 훨씬 빠릅니다. false 평가되는 경우 mySwitch.TraceError 호출WriteLine(String)하지 않기 때문입니다. 두 번째 예제는 추적 출력이 false 생성되지 않는 경우에도 mySwitch.TraceError 항상 호출WriteLineIf(Boolean, String)합니다. 이로 인해 임의로 복잡한 코드를 불필요하게 실행할 수 있습니다.

첫 번째 예제

if(mySwitch.TraceError)
    Trace.WriteLine("aNumber = " + aNumber + " out of range");

두 번째 예제

Trace.WriteLineIf(mySwitch.TraceError, "aNumber = " + aNumber + " out of range");

추가 정보

적용 대상

WriteLineIf(Boolean, Object)

조건이 ToString()있는 경우 개체 메서드의 값을 컬렉션의 Listeners 추적 수신기에 true 씁니다.

public:
 static void WriteLineIf(bool condition, System::Object ^ value);
[System.Diagnostics.Conditional("TRACE")]
public static void WriteLineIf(bool condition, object value);
[<System.Diagnostics.Conditional("TRACE")>]
static member WriteLineIf : bool * obj -> unit
Public Shared Sub WriteLineIf (condition As Boolean, value As Object)

매개 변수

condition
Boolean

true메시지를 작성하려면 이고, 그렇지 않으면 . false

value
Object

Object 이름이 .로 전송되는 이름Listeners입니다.

특성

예제

다음 예제에서는 명명TraceSwitch된 .generalSwitch 이 스위치는 코드 샘플 외부에서 설정됩니다.

스위치가 더 높은 값으로 TraceLevelError 설정된 경우 예제에서는 첫 번째 오류 메시지를 Listeners출력합니다. 컬렉션에 수신기 Listeners 를 추가하는 방법에 대한 자세한 내용은 클래스를 TraceListenerCollection 참조하세요.

그런 다음, 설정된 TraceLevel경우 Verbose 예제에서는 첫 번째 메시지와 동일한 줄에 개체의 이름을 출력합니다. 두 번째 메시지 뒤에 줄 종결자가 잇습니다.

// Class-level declaration.
 // Create a TraceSwitch.
 static TraceSwitch generalSwitch = new TraceSwitch("General", "Entire Application");

 static public void MyErrorMethod(Object myObject) {
    // Write the message if the TraceSwitch level is set to Error or higher.
    Trace.WriteIf(generalSwitch.TraceError, "Invalid object. ");

    // Write a second message if the TraceSwitch level is set to Verbose.
    Trace.WriteLineIf(generalSwitch.TraceVerbose, myObject);
 }
' Class-level declaration.
' Create a TraceSwitch.
Private Shared generalSwitch As New TraceSwitch("General", "Entire Application")


Public Shared Sub MyErrorMethod(myObject As Object)
    ' Write the message if the TraceSwitch level is set to Error or higher.
    Trace.WriteIf(generalSwitch.TraceError, "Invalid object. ")
    
    ' Write a second message if the TraceSwitch level is set to Verbose.
    Trace.WriteLineIf(generalSwitch.TraceVerbose, myObject)
End Sub

설명

기본적으로 출력은 .의 DefaultTraceListener인스턴스에 기록됩니다.

이 메서드는 WriteLine 추적 수신기의 메서드를 호출합니다.

상속자 참고

문을 사용하는 WriteLineIf(Boolean, String) 대신 문을 사용하여 If...Then 애플리케이션 계측의 성능 저하를 최소화할 수 있습니다. 다음 두 코드 예제에서는 동일한 디버깅 메시지를 보냅니다. 그러나 첫 번째 예제는 추적이 꺼져 있을 때 훨씬 빠릅니다. false 평가되는 경우 mySwitch.TraceError 호출WriteLine(String)하지 않기 때문입니다. 두 번째 예제는 추적 출력이 false 생성되지 않는 경우에도 mySwitch.TraceError 항상 호출WriteLineIf(Boolean, String)합니다. 이로 인해 임의로 복잡한 코드를 불필요하게 실행할 수 있습니다.

첫 번째 예제

if(mySwitch.TraceError)
    Trace.WriteLine("aNumber = " + aNumber + " out of range");

두 번째 예제

Trace.WriteLineIf(mySwitch.TraceError, "aNumber = " + aNumber + " out of range");

추가 정보

적용 대상

WriteLineIf(Boolean, String)

조건이 Listeners있는 경우 컬렉션의 추적 수신기에 true 메시지를 씁니다.

public:
 static void WriteLineIf(bool condition, System::String ^ message);
[System.Diagnostics.Conditional("TRACE")]
public static void WriteLineIf(bool condition, string message);
[<System.Diagnostics.Conditional("TRACE")>]
static member WriteLineIf : bool * string -> unit
Public Shared Sub WriteLineIf (condition As Boolean, message As String)

매개 변수

condition
Boolean

true메시지를 작성하려면 이고, 그렇지 않으면 . false

message
String

쓸 메시지입니다.

특성

예제

다음 예제에서는 명명TraceSwitch된 .generalSwitch 이 스위치는 코드 샘플 외부에서 설정됩니다.

스위치가 더 높은 값으로 TraceLevelError 설정된 경우 예제에서는 첫 번째 오류 메시지를 Listeners출력합니다. 컬렉션에 수신기 Listeners 를 추가하는 방법에 대한 자세한 내용은 클래스를 TraceListenerCollection 참조하세요.

그런 다음, 설정된 TraceLevel경우 Verbose 예제에서는 첫 번째 메시지와 동일한 줄에 두 번째 오류 메시지를 출력합니다. 두 번째 메시지 뒤에 줄 종결자가 잇습니다.

// Class-level declaration.
 // Create a TraceSwitch.
 static TraceSwitch generalSwitch = new TraceSwitch("General", "Entire Application");

 static public void MyErrorMethod() {
    // Write the message if the TraceSwitch level is set to Error or higher.
    Trace.WriteIf(generalSwitch.TraceError, "My error message. ");

    // Write a second message if the TraceSwitch level is set to Verbose.
    Trace.WriteLineIf(generalSwitch.TraceVerbose, "My second error message.");
 }
' Class-level declaration.
' Create a TraceSwitch.
Private Shared generalSwitch As New TraceSwitch("General", "Entire Application")

Public Shared Sub MyErrorMethod()
    ' Write the message if the TraceSwitch level is set to Error or higher.
    Trace.WriteIf(generalSwitch.TraceError, "My error message. ")
    
    ' Write a second message if the TraceSwitch level is set to Verbose.
    Trace.WriteLineIf(generalSwitch.TraceVerbose, "My second error message.")
End Sub

설명

기본적으로 출력은 .의 DefaultTraceListener인스턴스에 기록됩니다.

이 메서드는 WriteLine 추적 수신기의 메서드를 호출합니다.

상속자 참고

문을 사용하는 WriteLineIf(Boolean, String) 대신 문을 사용하여 If...Then 애플리케이션 계측의 성능 저하를 최소화할 수 있습니다. 다음 두 코드 예제에서는 동일한 디버깅 메시지를 보냅니다. 그러나 첫 번째 예제는 추적이 꺼져 있을 때 훨씬 빠릅니다. false 평가되는 경우 mySwitch.TraceError 호출WriteLine(String)하지 않기 때문입니다. 두 번째 예제는 추적 출력이 false 생성되지 않는 경우에도 mySwitch.TraceError 항상 호출WriteLineIf(Boolean, String)합니다. 이로 인해 임의로 복잡한 코드를 불필요하게 실행할 수 있습니다.

첫 번째 예제

if(mySwitch.TraceError)
    Trace.WriteLine("aNumber = " + aNumber + " out of range");

두 번째 예제

Trace.WriteLineIf(mySwitch.TraceError, "aNumber = " + aNumber + " out of range");

추가 정보

적용 대상

WriteLineIf(Boolean, String, String)

조건이 Listeners있는 경우 컬렉션의 추적 수신기에 true 범주 이름 및 메시지를 씁니다.

public:
 static void WriteLineIf(bool condition, System::String ^ message, System::String ^ category);
[System.Diagnostics.Conditional("TRACE")]
public static void WriteLineIf(bool condition, string message, string category);
[<System.Diagnostics.Conditional("TRACE")>]
static member WriteLineIf : bool * string * string -> unit
Public Shared Sub WriteLineIf (condition As Boolean, message As String, category As String)

매개 변수

condition
Boolean

true메시지를 작성하려면 이고, 그렇지 않으면 . false

message
String

쓸 메시지입니다.

category
String

출력을 구성하는 데 사용되는 범주 이름입니다.

특성

예제

다음 예제에서는 명명TraceSwitch된 .generalSwitch 이 스위치는 코드 샘플 외부에서 설정됩니다.

스위치가 더 높은 값으로 TraceLevelError 설정된 경우 예제에서는 첫 번째 오류 메시지를 Listeners출력합니다. 컬렉션에 수신기 Listeners 를 추가하는 방법에 대한 자세한 내용은 클래스를 TraceListenerCollection 참조하세요.

그런 다음, 설정된 TraceLevel경우 Verbose 예제에서는 두 번째 오류 메시지와 첫 번째 메시지와 category 동일한 줄에 출력합니다. 두 번째 메시지 뒤에 줄 종결자가 잇습니다.

// Class-level declaration.
 // Create a TraceSwitch.
 static TraceSwitch generalSwitch = new TraceSwitch("General", "Entire Application");

 static public void MyErrorMethod(string category) {
    // Write the message if the TraceSwitch level is set to Error or higher.
    Trace.WriteIf(generalSwitch.TraceError, "My error message. ");

    // Write a second message if the TraceSwitch level is set to Verbose.
    Trace.WriteLineIf(generalSwitch.TraceVerbose, "My second error message.", category);
 }
' Class-level declaration.
' Create a TraceSwitch.
Private Shared generalSwitch As New TraceSwitch("General", "Entire Application")

Public Shared Sub MyErrorMethod(category As String)
    ' Write the message if the TraceSwitch level is set to Error or higher.
    Trace.WriteIf(generalSwitch.TraceError, "My error message. ")
    
    ' Write a second message if the TraceSwitch level is set to Verbose.
    Trace.WriteLineIf(generalSwitch.TraceVerbose, _
        "My second error message.", category)
End Sub

설명

기본적으로 출력은 .의 DefaultTraceListener인스턴스에 기록됩니다.

매개 변수를 category 사용하여 출력 메시지를 그룹화할 수 있습니다.

이 메서드는 WriteLine 추적 수신기의 메서드를 호출합니다.

상속자 참고

문을 사용하는 WriteLineIf(Boolean, String) 대신 문을 사용하여 If...Then 애플리케이션 계측의 성능 저하를 최소화할 수 있습니다. 다음 두 코드 예제에서는 동일한 디버깅 메시지를 보냅니다. 그러나 첫 번째 예제는 추적이 꺼져 있을 때 훨씬 빠릅니다. false 평가되는 경우 mySwitch.TraceError 호출WriteLine(String)하지 않기 때문입니다. 두 번째 예제는 추적 출력이 false 생성되지 않는 경우에도 mySwitch.TraceError 항상 호출WriteLineIf(Boolean, String)합니다. 이로 인해 임의로 복잡한 코드를 불필요하게 실행할 수 있습니다.

첫 번째 예제

if(mySwitch.TraceError)
    Trace.WriteLine("aNumber = " + aNumber + " out of range");

두 번째 예제

Trace.WriteLineIf(mySwitch.TraceError, "aNumber = " + aNumber + " out of range");

추가 정보

적용 대상