TraceSwitch.Level Propriedade

Definição

Obtém ou define o nível de rastreamento que determina as mensagens que o comutador permite.

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

Valor da propriedade

Um dos TraceLevel valores que especifica o nível de mensagens permitidas pela opção.

Exceções

Level é definido para um valor que não é um dos valores TraceLevel.

Exemplos

O exemplo de código a seguir cria um novo TraceSwitch e usa a opção para determinar se as mensagens de erro devem ser impressas. A opção é criada no nível da classe. MyMethod gravará a primeira mensagem de erro se a Level propriedade estiver definida como TraceLevel.Error ou superior. No entanto, MyMethod não gravará a segunda mensagem de erro se for Level menor que TraceLevel.Verbose.

   // 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

Comentários

Para .NET Framework aplicativos, para definir o nível do seu TraceSwitch, edite o arquivo de configuração que corresponde ao nome do aplicativo. Nesse arquivo, você pode adicionar uma opção e definir seu valor, remover uma opção ou limpar todas as opções definidas anteriormente pelo aplicativo. O arquivo de configuração deve ser formatado como o exemplo a seguir:

<configuration>  
  <system.diagnostics>  
    <switches>  
      <add name="mySwitch" value="0" />  
      <add name="myNewSwitch" value="3" />  
      <remove name="mySwitch" />  
      <clear/>  
    </switches>  
  </system.diagnostics>  
</configuration>  

Você também pode usar texto para especificar o valor de uma opção. Por exemplo, true para um BooleanSwitch ou o texto que representa um valor de enumeração, como Error para um TraceSwitch. A linha <add name="mySwitch" value="Error" /> é equivalente a <add name="mySwitch" value="1" />.

O valor padrão da Level propriedade é TraceLevel.Off. Ou, para .NET Framework aplicativos, o nível será obtido do arquivo de configuração, se disponível.

Definir essa propriedade atualiza as TraceErrorpropriedades , TraceWarning, TraceInfoe TraceVerbose para refletir o novo valor.

Aplica-se a

Confira também