Share via


TraceSwitch.Level Vlastnost

Definice

Získá nebo nastaví úroveň trasování, která určuje zprávy, které přepínač umožňuje.

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

Hodnota vlastnosti

Jedna z TraceLevel hodnot, která určuje úroveň zpráv povolených přepínačem.

Výjimky

Level je nastavená na hodnotu, která není jednou z TraceLevel hodnot.

Příklady

Následující příklad kódu vytvoří nový TraceSwitch a pomocí přepínače určí, zda se mají vytisknout chybové zprávy. Přepínač se vytvoří na úrovni třídy. MyMethod zapíše první chybovou zprávu, pokud je vlastnost nastavena Level na TraceLevel.Error hodnotu nebo vyšší. Nezapíše ale druhou chybovou zprávu, MyMethod pokud Level je hodnota menší než 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

Poznámky

Pokud chcete nastavit úroveň aplikace rozhraní .NET Framework, upravte TraceSwitchkonfigurační soubor, který odpovídá názvu vaší aplikace. V tomto souboru můžete přidat přepínač a nastavit jeho hodnotu, odebrat přepínač nebo vymazat všechny přepínače, které aplikace předtím nastavovala. Konfigurační soubor by měl být naformátovaný jako v následujícím příkladu:

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

K zadání hodnoty přepínače můžete použít také text. Například true pro BooleanSwitch text nebo představující hodnotu výčtuTraceSwitch, například Error pro . Čára <add name="mySwitch" value="Error" /> je ekvivalentní k <add name="mySwitch" value="1" />.

Výchozí hodnota Level vlastnosti je TraceLevel.Off. Nebo u aplikací .NET Framework se úroveň získá z konfiguračního souboru, pokud je k dispozici.

Nastavení této vlastnosti aktualizuje TraceErrorvlastnosti , TraceWarning, TraceInfoa TraceVerbose tak, aby odrážely novou hodnotu.

Platí pro

Viz také