다음을 통해 공유


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 허용하는 메시지 수준을 지정하는 값 중 하나입니다.

예외

Level 는 값 중 하나가 아닌 값으로 TraceLevel 설정됩니다.

예제

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

//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 열거형 값을 나타내는 텍스트(예:ErrorTraceSwitch<add name="mySwitch" value="Error" /> 은 .에 해당합니다 <add name="mySwitch" value="1" />.

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

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

적용 대상

추가 정보