TraceSwitch.Level 속성

정의

스위치에서 허용하는 메시지를 결정하는 추적 수준을 가져오거나 설정합니다.

public:
 property System::Diagnostics::TraceLevel Level { System::Diagnostics::TraceLevel get(); void set(System::Diagnostics::TraceLevel value); };
public System.Diagnostics.TraceLevel Level { get; set; }
member this.Level : System.Diagnostics.TraceLevel with get, set
Public Property Level As TraceLevel

속성 값

스위치에서 TraceLevel 허용하는 메시지 수준을 지정하는 값 중 하나입니다.

예외

LevelTraceLevel 값 중 하나가 아닌 값으로 설정된 경우

예제

다음 코드 예제에서는 새 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( "mySwitch","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("mySwitch", "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("mySwitch", "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="0" />  
      <add name="myNewSwitch" value="3" />  
      <remove name="mySwitch" />  
      <clear/>  
    </switches>  
  </system.diagnostics>  
</configuration>  

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

기본값은 Level 속성은 TraceLevel.Off합니다. 또는 .NET Framework 앱의 경우 사용 가능한 경우 구성 파일에서 수준을 가져옵니다.

이 속성을 설정하면 TraceError, TraceWarning, TraceInfoTraceVerbose 속성이 새 값을 반영하도록 업데이트됩니다.

적용 대상

추가 정보