Debug.WriteIf 메서드

정의

조건이 true이면 Listeners 컬렉션의 추적 수신기에 디버그에 대한 정보를 씁니다.

오버로드

WriteIf(Boolean, Debug+WriteIfInterpolatedStringHandler)

가 이truecondition 컬렉션의 추적 수신기 Listeners 에 범주 이름 및 메시지를 씁니다.

WriteIf(Boolean, Object)

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

WriteIf(Boolean, String)

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

WriteIf(Boolean, Debug+WriteIfInterpolatedStringHandler, String)

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

WriteIf(Boolean, Object, String)

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

WriteIf(Boolean, String, String)

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

WriteIf(Boolean, Debug+WriteIfInterpolatedStringHandler)

Source:
Debug.cs
Source:
Debug.cs
Source:
Debug.cs

가 이truecondition 컬렉션의 추적 수신기 Listeners 에 범주 이름 및 메시지를 씁니다.

public:
 static void WriteIf(bool condition, System::Diagnostics::Debug::WriteIfInterpolatedStringHandler % message);
[System.Diagnostics.Conditional("DEBUG")]
public static void WriteIf (bool condition, ref System.Diagnostics.Debug.WriteIfInterpolatedStringHandler message);
[<System.Diagnostics.Conditional("DEBUG")>]
static member WriteIf : bool * WriteIfInterpolatedStringHandler -> unit
Public Shared Sub WriteIf (condition As Boolean, ByRef message As Debug.WriteIfInterpolatedStringHandler)

매개 변수

condition
Boolean

계산할 조건부 식입니다. 조건이 true이면 컬렉션의 추적 수신기에 값을 씁니다.

message
Debug.WriteIfInterpolatedStringHandler

가 인 경우 condition 쓸 메시지입니다 true.

특성

설명

이 오버로드는 성능을 향상시키기 위해 .NET 6에 도입되었습니다. 매개 변수를 사용하는 String 오버로드와 비교하여 이 오버로드는 메시지가 필요한 경우에만 보간된 문자열 서식 항목을 평가합니다.

기본적으로 출력은 의 DefaultTraceListenerinstance 기록됩니다.

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

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

추가 정보

적용 대상

WriteIf(Boolean, Object)

Source:
Debug.cs
Source:
Debug.cs
Source:
Debug.cs

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

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

매개 변수

condition
Boolean

계산할 조건부 식입니다. 조건이 true이면 컬렉션의 추적 수신기에 값을 씁니다.

value
Object

Listeners에 이름을 보낸 개체입니다.

특성

예제

다음 예제에서는 라는 generalSwitchTraceSwitch 만듭니다. 이 스위치는 코드 샘플 외부에서 설정됩니다.

스위치가 이상으로 설정된 TraceLevelError 경우 이 예제에서는 값 매개 변수 Listeners의 이름을 에 출력합니다. 컬렉션에 수신기 Listeners 를 추가하는 방법에 대한 자세한 내용은 클래스를 참조하세요 TraceListenerCollection .

그런 다음 가 TraceLevelVerbose설정된 경우 예제에서는 첫 번째 메시지와 동일한 줄에 메시지를 출력합니다. 줄 종결자는 두 번째 메시지를 따릅니다.

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

public:
   static void MyErrorMethod( Object^ myObject )
   {
      // Write the message if the TraceSwitch level is set to Error or higher.
      #if defined(DEBUG)
      Debug::WriteIf( generalSwitch->TraceError, myObject );
      
      // Write a second message if the TraceSwitch level is set to Verbose.
      Debug::WriteLineIf( generalSwitch->TraceVerbose, 
         " is not a valid value for this method." );
      #endif
   }
// 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.
    Debug.WriteIf(generalSwitch.TraceError, myObject);

    // Write a second message if the TraceSwitch level is set to Verbose.
    Debug.WriteLineIf(generalSwitch.TraceVerbose, " is not a valid value for this method.");
}
' 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.
    Debug.WriteIf(generalSwitch.TraceError, myObject)
    
    ' Write a second message if the TraceSwitch level is set to Verbose.
    Debug.WriteLineIf(generalSwitch.TraceVerbose, " is not a valid value for this method.")
End Sub

설명

기본적으로 출력은 의 DefaultTraceListenerinstance 기록됩니다.

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

상속자 참고

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

첫 번째 예제:

if(mySwitch.TraceError)
    Debug.Write("aNumber = " + aNumber + " out of range");

두 번째 예제:

Debug.WriteIf(mySwitch.TraceError, "aNumber = " + aNumber + " out of range");

추가 정보

적용 대상

WriteIf(Boolean, String)

Source:
Debug.cs
Source:
Debug.cs
Source:
Debug.cs

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

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

매개 변수

condition
Boolean

계산할 조건부 식입니다. 조건이 true이면 컬렉션의 추적 수신기에 메시지를 씁니다.

message
String

쓸 메시지입니다.

특성

예제

다음 예제에서는 라는 generalSwitchTraceSwitch 만듭니다. 이 스위치는 코드 샘플 외부에서 설정됩니다.

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

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

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

public:
   static void MyErrorMethod()
   {
      // Write the message if the TraceSwitch level is set to Error or higher.
      #if defined(DEBUG)
      Debug::WriteIf( generalSwitch->TraceError, "My error message. " );
      
      // Write a second message if the TraceSwitch level is set to Verbose.
      Debug::WriteIf( generalSwitch->TraceVerbose, 
         "My second error message." );
      #endif
   }
// Class-level declaration.
// Create a TraceSwitch.
TraceSwitch generalSwitch = new TraceSwitch("General", "Entire Application");

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

    // Write a second message if the TraceSwitch level is set to Verbose.
    Debug.WriteIf(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.
    Debug.WriteIf(generalSwitch.TraceError, "My error message. ")
    
    ' Write a second message if the TraceSwitch level is set to Verbose.
    Debug.WriteIf(generalSwitch.TraceVerbose, "My second error message.")
End Sub

설명

기본적으로 출력은 의 DefaultTraceListenerinstance 기록됩니다.

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

상속자 참고

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

첫 번째 예제:

if(mySwitch.TraceError)
    Debug.Write("aNumber = " + aNumber + " out of range");

두 번째 예제:

Debug.WriteIf(mySwitch.TraceError, "aNumber = " + aNumber + " out of range");

추가 정보

적용 대상

WriteIf(Boolean, Debug+WriteIfInterpolatedStringHandler, String)

Source:
Debug.cs
Source:
Debug.cs
Source:
Debug.cs

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

public:
 static void WriteIf(bool condition, System::Diagnostics::Debug::WriteIfInterpolatedStringHandler % message, System::String ^ category);
[System.Diagnostics.Conditional("DEBUG")]
public static void WriteIf (bool condition, ref System.Diagnostics.Debug.WriteIfInterpolatedStringHandler message, string? category);
[<System.Diagnostics.Conditional("DEBUG")>]
static member WriteIf : bool * WriteIfInterpolatedStringHandler * string -> unit
Public Shared Sub WriteIf (condition As Boolean, ByRef message As Debug.WriteIfInterpolatedStringHandler, category As String)

매개 변수

condition
Boolean

계산할 조건부 식입니다. 조건이 true이면 컬렉션의 추적 수신기에 메시지를 씁니다.

message
Debug.WriteIfInterpolatedStringHandler

쓸 메시지입니다.

category
String

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

특성

설명

이 오버로드는 성능을 향상시키기 위해 .NET 6에 도입되었습니다. 매개 변수를 사용하는 String 오버로드와 비교하여 이 오버로드는 메시지가 필요한 경우에만 보간된 문자열 서식 항목을 평가합니다.

기본적으로 출력은 의 DefaultTraceListenerinstance 기록됩니다.

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

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

추가 정보

적용 대상

WriteIf(Boolean, Object, String)

Source:
Debug.cs
Source:
Debug.cs
Source:
Debug.cs

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

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

매개 변수

condition
Boolean

계산할 조건부 식입니다. 조건이 true이면 컬렉션의 추적 수신기에 범주 이름과 값을 씁니다.

value
Object

Listeners에 이름을 보낸 개체입니다.

category
String

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

특성

예제

다음 예제에서는 라는 generalSwitchTraceSwitch 만듭니다. 이 스위치는 코드 샘플 외부에서 설정됩니다.

스위치가 로 TraceLevelVerbose설정된 경우 예제에서는 및 categorymyObject 이름을 에 Listeners출력합니다. 컬렉션에 수신기 Listeners 를 추가하는 방법에 대한 자세한 내용은 클래스를 참조하세요 TraceListenerCollection .

그런 다음 가 TraceLevel 이상으로 설정된 Error 경우 예제에서는 첫 번째 메시지와 동일한 줄에 두 번째 오류 메시지를 출력합니다. 줄 종결자는 두 번째 메시지를 따릅니다.

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

public:
   static void MyErrorMethod( Object^ myObject, String^ category )
   {
      // Write the message if the TraceSwitch level is set to Error or higher.
      #if defined(DEBUG)
      Debug::WriteIf( generalSwitch->TraceVerbose, myObject, category );
      
      // Write a second message if the TraceSwitch level is set to Verbose.
      Debug::WriteLineIf( generalSwitch->TraceError, 
         " Object is not valid for this category." );
      #endif
   }
// 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 Verbose.
    Debug.WriteIf(generalSwitch.TraceVerbose, myObject, category);

    // Write a second message if the TraceSwitch level is set to Error or higher.
    Debug.WriteLineIf(generalSwitch.TraceError, " Object is not valid for this 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 Verbose.
    Debug.WriteIf(generalSwitch.TraceVerbose, myObject, category)
    
    ' Write a second message if the TraceSwitch level is set to Error or higher.
    Debug.WriteLineIf(generalSwitch.TraceError, " Object is not valid for this category.")
End Sub

설명

기본적으로 출력은 의 DefaultTraceListenerinstance 기록됩니다.

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

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

상속자 참고

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

첫 번째 예제:

if(mySwitch.TraceError)
    Debug.Write("aNumber = " + aNumber + " out of range");

두 번째 예제:

Debug.WriteIf(mySwitch.TraceError, "aNumber = " + aNumber + " out of range");

추가 정보

적용 대상

WriteIf(Boolean, String, String)

Source:
Debug.cs
Source:
Debug.cs
Source:
Debug.cs

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

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

매개 변수

condition
Boolean

계산할 조건부 식입니다. 조건이 true이면 컬렉션의 추적 수신기에 범주 이름과 메시지를 씁니다.

message
String

쓸 메시지입니다.

category
String

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

특성

예제

다음 예제에서는 라는 를 TraceSwitchgeneralSwitch만듭니다. 이 스위치는 코드 샘플 외부에서 설정됩니다.

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

그런 다음 이 이상으로 설정된 Error 경우 TraceLevel 예제에서는 첫 번째 메시지와 동일한 줄에 두 번째 오류 메시지를 출력합니다. 줄 종결자는 두 번째 메시지를 따릅니다.

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

public:
   static void MyErrorMethod( Object^ myObject, String^ category )
   {
      // Write the message if the TraceSwitch level is set to Error or higher.
      #if defined(DEBUG)
      Debug::WriteIf( generalSwitch->TraceVerbose, String::Concat( myObject, 
         " is not a valid object for category: " ), category );
      
      // Write a second message if the TraceSwitch level is set to Verbose.
      Debug::WriteLineIf( generalSwitch->TraceError, 
         " Please use a different category." );
      #endif
   }
// 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 Verbose.
    Debug.WriteIf(generalSwitch.TraceVerbose, myObject.ToString() +
       " is not a valid object for category: ", category);

    // Write a second message if the TraceSwitch level is set to Error or higher.
    Debug.WriteLineIf(generalSwitch.TraceError, " Please use a different 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 Verbose.
    Debug.WriteIf(generalSwitch.TraceVerbose, myObject.ToString() & _
        " is not a valid object for category: ", category)
    
    ' Write a second message if the TraceSwitch level is set to Error or higher.
    Debug.WriteLineIf(generalSwitch.TraceError, " Please use a different category.")
End Sub

설명

기본적으로 출력은 의 DefaultTraceListenerinstance 기록됩니다.

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

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

상속자 참고

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

첫 번째 예제:

if(mySwitch.TraceError)
    Debug.Write("aNumber = " + aNumber + " out of range");

두 번째 예제:

Debug.WriteIf(mySwitch.TraceError, "aNumber = " + aNumber + " out of range");

추가 정보

적용 대상