다음을 통해 공유


Trace.Assert 메서드

정의

조건을 확인합니다. 조건이면 false메시지를 출력하고 호출 스택을 표시하는 메시지 상자를 표시합니다.

오버로드

Name Description
Assert(Boolean)

조건을 확인합니다. 조건이 false면 호출 스택을 표시하는 메시지 상자를 표시합니다.

Assert(Boolean, String)

조건을 확인합니다. 조건이면 false지정된 메시지를 출력하고 호출 스택을 표시하는 메시지 상자를 표시합니다.

Assert(Boolean, String, String)

조건을 확인합니다. 조건이면 false지정된 두 개의 메시지를 출력하고 호출 스택을 표시하는 메시지 상자를 표시합니다.

Assert(Boolean)

Source:
Trace.cs
Source:
Trace.cs
Source:
Trace.cs
Source:
Trace.cs
Source:
Trace.cs

조건을 확인합니다. 조건이 false면 호출 스택을 표시하는 메시지 상자를 표시합니다.

public:
 static void Assert(bool condition);
[System.Diagnostics.Conditional("TRACE")]
[System.Runtime.CompilerServices.OverloadResolutionPriority(-1)]
public static void Assert(bool condition);
[System.Diagnostics.Conditional("TRACE")]
public static void Assert(bool condition);
[<System.Diagnostics.Conditional("TRACE")>]
[<System.Runtime.CompilerServices.OverloadResolutionPriority(-1)>]
static member Assert : bool -> unit
[<System.Diagnostics.Conditional("TRACE")>]
static member Assert : bool -> unit
Public Shared Sub Assert (condition As Boolean)

매개 변수

condition
Boolean

계산할 조건부 식입니다. 조건이면 true오류 메시지가 전송되지 않고 메시지 상자가 표시되지 않습니다.

특성

예제

다음 예제에서는 배열에 대한 인덱스 만듭니다. 그런 다음 인덱스의 값을 설정하는 일부 작업이 수행됩니다. 다음으로 코드는 인덱스 값이 유효한지 확인하기 위해 호출 Assert 합니다. 유효 Assert 하지 않으면 호출 스택이 출력됩니다.

// Create an index for an array.
int index;

void Method()
{
    // Perform some action that sets the index.

    // Test that the index value is valid.
    Trace.Assert(index > -1);
}
' Create an index for an array.
Protected index As Integer    

Protected Sub Method()
    ' Perform some action that sets the index.
    ' Test that the index value is valid. 
    Trace.Assert(index > -1)
End Sub

설명

릴리스 빌드에서 Trace.Assert 어설션을 수행하려면 이 메서드를 사용합니다. 이 메서드는 Debug.Assert 디버그 빌드에서만 작동합니다. 자세한 내용은 관리 코드 어설션을 참조하세요.

일반적으로 Assert(Boolean) 이 메서드는 프로그램 개발 중에 논리 오류를 식별하는 데 사용됩니다. Assert(Boolean) 는 조건을 평가합니다. 결과가 있으면 false컬렉션에 실패 메시지를 Listeners 보냅니다. 컬렉션을 추가 TraceListener 하거나 컬렉션에서 Listeners 제거하여 이 동작을 사용자 지정할 수 있습니다.

애플리케이션이 사용자 인터페이스 모드에서 실행되면 파일 및 줄 번호가 있는 호출 스택을 표시하는 메시지 상자가 표시됩니다. 메시지 상자에는 중단, 다시 시도무시라는 세 개의 단추가 있습니다. 중단 단추를 클릭하면 애플리케이션이 종료됩니다. 다시 시도를 클릭하면 애플리케이션이 디버거에서 실행 중인 경우 디버거의 코드로 보내거나, 그렇지 않은 경우 디버거를 열도록 제안합니다. 무시를 클릭하면 코드의 다음 명령이 계속됩니다.

메모

메시지 상자의 표시는 .의 DefaultTraceListener존재에 따라 달라집니다. 컬렉션에 DefaultTraceListenerListeners 없는 경우 메시지 상자가 표시되지 않습니다. DefaultTraceListener 속성(System.Diagnostics.Trace.Listeners.Clear())에서 Listeners 메서드를 Clear 호출하여 제거할 수 있습니다. .NET Framework 앱의 경우 앱의 <구성 파일에서 clear> 요소<제거> 요소를 사용할 수도 있습니다.

.NET Framework 앱의 경우 애플리케이션의 이름에 DefaultTraceListener 해당하는 구성 파일의 동작을 변경할 수 있습니다. 이 파일에서 어설션 메시지 상자를 사용하거나 사용하지 않도록 설정하거나 속성을 설정할 DefaultTraceListener.LogFileName 수 있습니다. 구성 파일의 형식은 다음과 같이 지정해야 합니다.

<configuration>
  <system.diagnostics>
    <switches>
      <add name="mySwitch" value="4"/>
    </switches>
    <trace autoflush="false" indentsize="4"/>
    <assert assertuienabled="true" logfilename=".\TraceLog.txt"/>
  </system.diagnostics>
</configuration>

추가 정보

적용 대상

Assert(Boolean, String)

Source:
Trace.cs
Source:
Trace.cs
Source:
Trace.cs
Source:
Trace.cs
Source:
Trace.cs

조건을 확인합니다. 조건이면 false지정된 메시지를 출력하고 호출 스택을 표시하는 메시지 상자를 표시합니다.

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

매개 변수

condition
Boolean

계산할 조건부 식입니다. 조건이면 true지정된 메시지가 전송되지 않고 메시지 상자가 표시되지 않습니다.

message
String

컬렉션에 보낼 메시지입니다 Listeners .

특성

예제

다음 예제에서는 매개 변수가 type 유효한지 확인합니다. 전달된 typenullAssert 메시지가 있으면 메시지를 출력합니다.

public static void MyMethod(Type type, Type baseType)
{
    Trace.Assert(type != null, "Type parameter is null");

    // Perform some processing.
}
Public Shared Sub MyMethod(type As Type, baseType As Type)
    Trace.Assert( Not (type Is Nothing), "Type parameter is null")

    ' Perform some processing.
End Sub

설명

릴리스 빌드에서 Trace.Assert 어설션을 수행하려면 이 메서드를 사용합니다. 이 메서드는 Debug.Assert 디버그 빌드에서만 작동합니다. 자세한 내용은 관리 코드 어설션을 참조하세요.

일반적으로 Assert(Boolean, String) 이 메서드는 프로그램 개발 중에 논리 오류를 식별하는 데 사용됩니다. Assert(Boolean, String) 는 조건을 평가합니다. 결과가 있으면 false지정된 진단 메시지를 컬렉션에 Listeners 보냅니다. 컬렉션을 추가 TraceListener 하거나 컬렉션에서 Listeners 제거하여 이 동작을 사용자 지정할 수 있습니다.

애플리케이션이 사용자 인터페이스 모드에서 실행되면 파일 및 줄 번호가 있는 호출 스택을 표시하는 메시지 상자가 표시됩니다. 메시지 상자에는 중단, 다시 시도무시라는 세 개의 단추가 있습니다. 중단 단추를 클릭하면 애플리케이션이 종료됩니다. 다시 시도를 클릭하면 애플리케이션이 디버거에서 실행 중인 경우 디버거의 코드로 보내거나, 그렇지 않은 경우 디버거를 열도록 제안합니다. 무시를 클릭하면 코드의 다음 명령이 계속됩니다.

메모

메시지 상자의 표시는 .의 DefaultTraceListener존재에 따라 달라집니다. 컬렉션에 DefaultTraceListenerListeners 없는 경우 메시지 상자가 표시되지 않습니다. DefaultTraceListener 속성(System.Diagnostics.Trace.Listeners.Clear())에서 Listeners 메서드를 Clear 호출하여 제거할 수 있습니다. .NET Framework 앱의 경우 앱의 <구성 파일에서 clear> 요소<제거> 요소를 사용할 수도 있습니다.

.NET Framework 앱의 경우 애플리케이션의 이름에 DefaultTraceListener 해당하는 구성 파일의 동작을 변경할 수 있습니다. 이 파일에서 어설션 메시지 상자를 사용하거나 사용하지 않도록 설정하거나 속성을 설정할 DefaultTraceListener.LogFileName 수 있습니다. 구성 파일의 형식은 다음과 같이 지정해야 합니다.

<configuration>
  <system.diagnostics>
    <switches>
      <add name="mySwitch" value="4"/>
    </switches>
    <trace autoflush="false" indentsize="4"/>
    <assert assertuienabled="true" logfilename=".\TraceLog.txt"/>
  </system.diagnostics>
</configuration>

추가 정보

적용 대상

Assert(Boolean, String, String)

Source:
Trace.cs
Source:
Trace.cs
Source:
Trace.cs
Source:
Trace.cs
Source:
Trace.cs

조건을 확인합니다. 조건이면 false지정된 두 개의 메시지를 출력하고 호출 스택을 표시하는 메시지 상자를 표시합니다.

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

매개 변수

condition
Boolean

계산할 조건부 식입니다. 조건이면 true지정된 메시지가 전송되지 않고 메시지 상자가 표시되지 않습니다.

message
String

컬렉션에 보낼 메시지입니다 Listeners .

detailMessage
String

컬렉션에 보낼 자세한 메시지입니다 Listeners .

특성

예제

다음 예제에서는 매개 변수가 type 유효한지 확인합니다. 전달된 typenullAssert 메시지가 있으면 메시지를 출력합니다.

public static void MyMethod(Type type, Type baseType)
{
    Trace.Assert(type != null, "Type parameter is null",
       "Can't get object for null type");

    // Perform some processing.
}
Public Shared Sub MyMethod(type As Type, baseType As Type)
    Trace.Assert( Not (type Is Nothing), "Type parameter is null", _
        "Can't get object for null type")

    ' Perform some processing.
End Sub

설명

릴리스 빌드에서 Trace.Assert 어설션을 수행하려면 이 메서드를 사용합니다. 이 메서드는 Debug.Assert 디버그 빌드에서만 작동합니다. 자세한 내용은 관리 코드 어설션을 참조하세요.

일반적으로 Assert(Boolean, String, String) 이 메서드는 프로그램 개발 중에 논리 오류를 식별하는 데 사용됩니다. Assert 는 조건을 평가합니다. 결과가 있으면 false지정된 진단 메시지와 자세한 메시지를 컬렉션에 Listeners 보냅니다. 컬렉션을 추가 TraceListener 하거나 컬렉션에서 Listeners 제거하여 이 동작을 사용자 지정할 수 있습니다.

애플리케이션이 사용자 인터페이스 모드에서 실행되면 파일 및 줄 번호가 있는 호출 스택을 표시하는 메시지 상자가 표시됩니다. 메시지 상자에는 중단, 다시 시도무시라는 세 개의 단추가 있습니다. 중단 단추를 클릭하면 애플리케이션이 종료됩니다. 다시 시도를 클릭하면 애플리케이션이 디버거에서 실행 중인 경우 디버거의 코드로 보내거나, 그렇지 않은 경우 디버거를 열도록 제안합니다. 무시를 클릭하면 코드의 다음 명령이 계속됩니다.

메모

메시지 상자의 표시는 .의 DefaultTraceListener존재에 따라 달라집니다. 컬렉션에 DefaultTraceListenerListeners 없는 경우 메시지 상자가 표시되지 않습니다. DefaultTraceListener 속성(System.Diagnostics.Trace.Listeners.Clear())에서 Listeners 메서드를 Clear 호출하여 제거할 수 있습니다. .NET Framework 앱의 경우 앱의 <구성 파일에서 clear> 요소<제거> 요소를 사용할 수도 있습니다.

.NET Framework 앱의 경우 애플리케이션의 이름에 DefaultTraceListener 해당하는 구성 파일의 동작을 변경할 수 있습니다. 이 파일에서 어설션 메시지 상자를 사용하거나 사용하지 않도록 설정하거나 속성을 설정할 DefaultTraceListener.LogFileName 수 있습니다. 구성 파일의 형식은 다음과 같이 지정해야 합니다.

<configuration>
  <system.diagnostics>
    <switches>
      <add name="mySwitch" value="4"/>
    </switches>
    <trace autoflush="false" indentsize="4"/>
    <assert assertuienabled="true" logfilename=".\TraceLog.txt"/>
  </system.diagnostics>
</configuration>

추가 정보

적용 대상