BooleanSwitch 클래스

정의

디버깅 및 추적 출력을 제어하는 간단한 켜기/끄기 스위치를 제공합니다.

public ref class BooleanSwitch : System::Diagnostics::Switch
public class BooleanSwitch : System.Diagnostics.Switch
type BooleanSwitch = class
    inherit Switch
Public Class BooleanSwitch
Inherits Switch
상속
BooleanSwitch

예제

다음 예제에서는 BooleanSwitch 스위치를 사용 하는 오류 메시지를 출력할 것인지 여부를 결정 합니다. 클래스 수준에서 스위치를 만드세요. 합니다 Main 메서드를 위치로 전달 MyMethod오류 메시지를 인쇄 하 고 오류가 발생 합니다.

public ref class BooleanSwitchTest
{
private:

   /* Create a BooleanSwitch for data.*/
   static BooleanSwitch^ dataSwitch = gcnew BooleanSwitch( "Data","DataAccess module" );

public:
   static void MyMethod( String^ location )
   {
      
      //Insert code here to handle processing.
      if ( dataSwitch->Enabled )
            Console::WriteLine( "Error happened at {0}", location );
   }

};

int main()
{
   
   //Run the method which writes an error message specifying the location of the error.
   BooleanSwitchTest::MyMethod( "in main" );
}
// Class level declaration.
/* Create a BooleanSwitch for data.*/
static BooleanSwitch dataSwitch = new BooleanSwitch("Data", "DataAccess module");

static public void MyMethod(string location)
{
    //Insert code here to handle processing.
    if (dataSwitch.Enabled)
        Console.WriteLine("Error happened at " + location);
}

public static void Main(string[] args)
{
    //Run the method which writes an error message specifying the location of the error.
    MyMethod("in Main");
}
' Class level declaration.
' Create a BooleanSwitch for data. 
Private Shared dataSwitch As New BooleanSwitch("Data", "DataAccess module")


Public Shared Sub MyMethod(location As String)
    ' Insert code here to handle processing.
    If dataSwitch.Enabled Then
        Console.WriteLine(("Error happened at " + location))
    End If
End Sub

' Entry point which delegates to C-style main function.
Public Overloads Shared Sub Main()
    Main(System.Environment.GetCommandLineArgs())
End Sub
 
Overloads Public Shared Sub Main(args() As String)
    ' Run the method which writes an error message specifying the location of the error.
    MyMethod("in Main")
End Sub

설명

중요도에 따라 메시지를 사용할지 여부를 Boolean 추적 스위치를 사용할 수 있습니다. 사용 된 Enabled 스위치의 현재 값을 검색할 속성입니다.

코드에서 을 BooleanSwitch 만들고 속성을 직접 설정 Enabled 하여 코드의 특정 섹션을 계측할 수 있습니다.

.NET Framework 앱의 경우 애플리케이션 구성 파일을 통해 를 BooleanSwitch 사용하거나 사용하지 않도록 설정한 다음, 애플리케이션에서 구성된 BooleanSwitch 값을 사용할 수도 있습니다. 구성 하는 BooleanSwitch, 애플리케이션의 이름에 해당 하는 구성 파일을 편집 합니다. 이 파일에 있습니다 수 추가 또는 제거 스위치를, 스위치의 값을 설정 하거나 스위치 애플리케이션에서 이전에 설정한 모든 선택을 취소 합니다. 다음 예제와 같이 구성 파일의 형식은 같아야 합니다.

<configuration>  
  <system.diagnostics>  
    <switches>  
      <add name="mySwitch" value="1"/>  
    </switches>  
  </system.diagnostics>  
</configuration>  

이 예제에서는 구성 섹션 정의 BooleanSwitch 사용 하 여는 DisplayName 속성이로 설정 mySwitch 하며 Enabled 값으로 설정 true합니다. .NET Framework 애플리케이션 내에서 다음 코드 예제와 같이 이름이 같은 을 BooleanSwitch 만들어 구성된 스위치 값을 사용할 수 있습니다.

private:
    static BooleanSwitch^ boolSwitch = gcnew BooleanSwitch("mySwitch",
        "Switch in config file");

public:
    static void Main( )
    {
        //...
        Console::WriteLine("Boolean switch {0} configured as {1}",
            boolSwitch->DisplayName, ((Boolean^)boolSwitch->Enabled)->ToString());
        if (boolSwitch->Enabled)
        {
            //...
        }
    }
private static BooleanSwitch boolSwitch = new BooleanSwitch("mySwitch",
    "Switch in config file");

public static void Main()
{
    //...
    Console.WriteLine("Boolean switch {0} configured as {1}",
        boolSwitch.DisplayName, boolSwitch.Enabled.ToString());
    if (boolSwitch.Enabled)
    {
        //...
    }
}
Private Shared boolSwitch As new BooleanSwitch("mySwitch", _
    "Switch in config file")

Public Shared Sub Main( )
    '...
    Console.WriteLine("Boolean switch {0} configured as {1}",
        boolSwitch.DisplayName, boolSwitch.Enabled.ToString())
    If boolSwitch.Enabled = True Then
        '...
    End If
End Sub

.NET Core 및 .NET 5+ 앱 Enabled 의 경우 새 스위치의 속성은 기본적으로 로 false 설정됩니다.

.NET Framework 앱의 Enabled 경우 속성은 구성 파일에 지정된 값을 사용하여 설정됩니다. 스위치를 설정 하려면 0 값으로 구성 합니다 Enabled 속성을 false; 스위치를 설정 하려면 0이 아닌 값을 사용 하 여 구성 합니다 Enabled 속성을 true. BooleanSwitch 생성자가 구성 파일 Enabled 에서 초기 스위치 설정을 찾을 수 없는 경우 새 스위치의 속성이 로 false설정됩니다.

추적 또는 디버깅 스위치를 사용 하도록 설정 해야 합니다. 다음 구문은 특정 컴파일러입니다. C# 또는 Visual Basic 이외의 컴파일러를 사용 하면 컴파일러에 대 한 설명서를 참조 합니다.

  • C# 디버깅을 사용 하려면 다음을 추가 합니다 /d:DEBUG 플래그를 추가할 수 있습니다 하거나 코드를 컴파일할 때 컴파일러 명령줄 #define DEBUG 파일의 맨 위로 이동 합니다. Visual Basic에서 추가 된 /d:DEBUG=True 컴파일러 명령줄 플래그입니다.

  • C#에서 추적을 사용 하려면 추가 합니다 /d:TRACE 코드를 컴파일할 때 컴파일러 명령줄 플래그 #define TRACE 파일의 맨 위로 이동 합니다. Visual Basic에서 추가 된 /d:TRACE=True 컴파일러 명령줄 플래그입니다.

참고

이러한 디버그 하 고 사용 하는 경우 추적 컴파일러 스위치 필요 하지 않습니다는 BooleanSwitch 격리의 클래스입니다. 와 함께 필요한 Trace 또는 Debug 메서드는 조건부로 컴파일됩니다.

애플리케이션을 계측 하는 방법은 참조 하세요 DebugTrace입니다. 구성 및 추적 스위치를 사용 하는 방법에 대 한 자세한 내용은 참조 하세요. 추적 스위치합니다.

참고

성능 향상을 위해 할 수 있습니다 BooleanSwitch 멤버 static 클래스에서입니다.

생성자

BooleanSwitch(String, String)

지정된 표시 이름 및 설명을 사용하여 BooleanSwitch 클래스의 새 인스턴스를 초기화합니다.

BooleanSwitch(String, String, String)

지정된 표시 이름, 설명 및 기본 스위치 값을 사용하여 BooleanSwitch 클래스의 새 인스턴스를 초기화합니다.

속성

Attributes

애플리케이션 구성 파일에 정의된 사용자 지정 스위치 특성을 가져옵니다.

(다음에서 상속됨 Switch)
DefaultValue

생성자에 할당된 기본값을 가져옵니다.

(다음에서 상속됨 Switch)
Description

스위치에 대한 설명을 가져옵니다.

(다음에서 상속됨 Switch)
DisplayName

스위치를 식별하는 데 사용되는 이름을 가져옵니다.

(다음에서 상속됨 Switch)
Enabled

스위치가 활성화되는지 여부를 나타내는 값을 가져오거나 설정합니다.

SwitchSetting

이 스위치의 현재 설정을 가져오거나 설정합니다.

(다음에서 상속됨 Switch)
Value

스위치의 값을 가져오거나 설정합니다.

(다음에서 상속됨 Switch)

메서드

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetSupportedAttributes()

스위치에서 지원하는 사용자 지정 특성을 가져옵니다.

(다음에서 상속됨 Switch)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
OnSwitchSettingChanged()

SwitchSetting 속성이 변경될 때 호출됩니다.

(다음에서 상속됨 Switch)
OnValueChanged()

Value 속성의 새 값을 부울 값으로 구문 분석할 수 있는지 여부를 결정합니다.

OnValueChanged()

Value 속성이 변경될 때 호출됩니다.

(다음에서 상속됨 Switch)
Refresh()

추적 구성 데이터를 새로 고칩니다.

(다음에서 상속됨 Switch)
ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

적용 대상

추가 정보