TraceSwitch 생성자

정의

TraceSwitch 클래스의 새 인스턴스를 초기화합니다.

오버로드

TraceSwitch(String, String)

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

TraceSwitch(String, String, String)

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

TraceSwitch(String, String)

Source:
TraceSwitch.cs
Source:
TraceSwitch.cs
Source:
TraceSwitch.cs

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

public:
 TraceSwitch(System::String ^ displayName, System::String ^ description);
public TraceSwitch (string displayName, string? description);
public TraceSwitch (string displayName, string description);
new System.Diagnostics.TraceSwitch : string * string -> System.Diagnostics.TraceSwitch
Public Sub New (displayName As String, description As String)

매개 변수

displayName
String

사용자 인터페이스에 표시할 이름입니다.

description
String

스위치에 대한 설명입니다.

예제

다음 코드 예제에서는 새 TraceSwitch 를 만들고 스위치를 사용하여 오류 메시지를 인쇄할지 여부를 결정합니다. 스위치는 클래스 수준에서 생성 됩니다. MyMethod속성이 이상으로 설정된 TraceLevel.Error 경우 Level 첫 번째 오류 메시지를 씁니다. 그러나 가 MyMethod 보다 TraceLevel.Verbose작으면 Level 두 번째 오류 메시지를 작성하지 않습니다.

   // Class-level declaration.
   /* Create a TraceSwitch to use in the entire application.*/
private:
   static TraceSwitch^ mySwitch = gcnew TraceSwitch( "General", "Entire Application" );

public:
   static void MyMethod()
   {
      // Write the message if the TraceSwitch level is set to Error or higher.
      if ( mySwitch->TraceError )
         Console::WriteLine( "My error message." );
      
      // Write the message if the TraceSwitch level is set to Verbose.
      if ( mySwitch->TraceVerbose )
         Console::WriteLine( "My second error message." );
   }

   static void main()
   {
      // Run the method that prints error messages based on the switch level.
      MyMethod();
   }
//Class-level declaration.
/* Create a TraceSwitch to use in the entire application.*/
static TraceSwitch mySwitch = new TraceSwitch("General", "Entire Application");

static public void MyMethod()
{
    // Write the message if the TraceSwitch level is set to Error or higher.
    if (mySwitch.TraceError)
        Console.WriteLine("My error message.");

    // Write the message if the TraceSwitch level is set to Verbose.
    if (mySwitch.TraceVerbose)
        Console.WriteLine("My second error message.");
}

public static void Main(string[] args)
{
    // Run the method that prints error messages based on the switch level.
    MyMethod();
}
' Class-level declaration.
' Create a TraceSwitch to use in the entire application. 
Private Shared mySwitch As New TraceSwitch("General", "Entire Application")    

Public Shared Sub MyMethod()
    ' Write the message if the TraceSwitch level is set to Error or higher.
    If mySwitch.TraceError Then
        Console.WriteLine("My error message.")
    End If 
    ' Write the message if the TraceSwitch level is set to Verbose.
    If mySwitch.TraceVerbose Then
        Console.WriteLine("My second error message.")
    End If
End Sub

Public Shared Sub Main()
    ' Run the method that prints error messages based on the switch level.
    MyMethod()
End Sub

설명

.NET Framework 앱의 경우 의 TraceSwitch수준을 설정하려면 애플리케이션 이름에 해당하는 구성 파일을 편집합니다. 이 파일에서 스위치를 추가 하 고 해당 값을 설정, 스위치를 제거 하거나 지울 수 스위치 애플리케이션에서 이전에 설정한 모든 합니다. 다음 예제와 같이 구성 파일의 형식은 해야 합니다.

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

텍스트를 사용하여 스위치의 값을 지정할 수도 있습니다. 예를 들어 의 trueBooleanSwitch 경우 또는 열거형 값을 나타내는 텍스트(예: Error )입니다 TraceSwitch. 줄 <add name="mySwitch" value="Error" /><add name="mySwitch" value="1" />과 동일합니다.

애플리케이션에서 구성 된 스위치 수준에서 만들어 사용할 수 있습니다는 TraceSwitch 다음 예와에서 같이 동일한 이름을 사용 하 여:

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

public:
    static void Main(array<String^>^ args)
    {
        //...
        Console::WriteLine("Trace switch {0} configured as {1}",
        appSwitch->DisplayName, appSwitch->Level.ToString());
        if (appSwitch->TraceError)
        {
            //...
        }
    }
private static TraceSwitch appSwitch = new TraceSwitch("mySwitch",
    "Switch in config file");

public static void Main(string[] args)
{
    //...
    Console.WriteLine("Trace switch {0} configured as {1}",
    appSwitch.DisplayName, appSwitch.Level.ToString());
    if (appSwitch.TraceError)
    {
        //...
    }
}
Private Shared appSwitch As new TraceSwitch("mySwitch", _
    "Switch in config file")

Public Shared Sub Main(args As String())
    '...
    Console.WriteLine("Trace switch {0} configured as {1}",
    appSwitch.DisplayName, appSwitch.Level.ToString())
    If appSwitch.TraceError = True  Then
        '...
    End If
End Sub

이 생성자는 새 스위치의 속성을 로 TraceLevel.Off설정합니다Level. 또는 .NET Framework 앱의 경우 가능한 경우 구성 파일에서 스위치 설정을 가져옵니다.

클래스는 TraceSwitch 스위치의 를 TraceError테스트 Level 하는 , TraceWarning, TraceInfoTraceVerbose 속성을 제공합니다. 속성은 Level 스위치의 TraceLevel를 가져오거나 설정합니다.

참고

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

추가 정보

적용 대상

TraceSwitch(String, String, String)

Source:
TraceSwitch.cs
Source:
TraceSwitch.cs
Source:
TraceSwitch.cs

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

public:
 TraceSwitch(System::String ^ displayName, System::String ^ description, System::String ^ defaultSwitchValue);
public TraceSwitch (string displayName, string? description, string defaultSwitchValue);
public TraceSwitch (string displayName, string description, string defaultSwitchValue);
new System.Diagnostics.TraceSwitch : string * string * string -> System.Diagnostics.TraceSwitch
Public Sub New (displayName As String, description As String, defaultSwitchValue As String)

매개 변수

displayName
String

사용자 인터페이스에 표시할 이름입니다.

description
String

스위치에 대한 설명입니다.

defaultSwitchValue
String

스위치의 기본값입니다.

설명

매개 변수는 displayName 속성 값을 DisplayName 설정하는 데 사용되고, description 매개 변수는 속성 값을 Description 설정하는 데 사용되며 defaultSwitchValue , 매개 변수는 필드로 저장되고 첫 번째 참조에서 속성을 초기화하는 Value 데 사용됩니다. TraceSwitch(String, String) 자세한 내용 및 코드 예제는 생성자를 참조하세요.

적용 대상