TraceSwitch.TraceInfo Proprietà

Definizione

Ottiene un valore che indica se l'opzione consente i messaggi informativi.

public bool TraceInfo { get; }

Valore della proprietà

true se la proprietà Level è impostata su Info o Verbose; in caso contrario, false.

Esempio

L'esempio di codice seguente crea un nuovo TraceSwitch oggetto e usa l'opzione per determinare se generare messaggi di errore. L'opzione viene creata a livello di classe. MyMethod scrive il primo messaggio di errore se la Level proprietà è impostata su TraceLevel.Info o superiore. Tuttavia, MyMethod non scrive il secondo messaggio di errore se è Level minore di TraceLevel.Verbose.

//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 Info or higher.
    if (mySwitch.TraceInfo)
        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();
}

Commenti

È possibile usare le TraceErrorproprietà , TraceWarning, TraceInfoe TraceVerbose insieme Debug alle classi e Trace per generare tutti i messaggi con un'importanza specificata o superiore. Quando la Level proprietà è impostata su TraceLevel.Warning, vengono generati messaggi informativi, avvisi e messaggi di gestione degli errori.

Si applica a

Prodotto Versioni
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

Vedi anche