TraceSwitch.TraceInfo Proprietà
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Ottiene un valore che indica se l'opzione consente i messaggi informativi.
public:
property bool TraceInfo { bool get(); };
public bool TraceInfo { get; }
member this.TraceInfo : bool
Public ReadOnly Property TraceInfo As Boolean
true
se la proprietà Level è impostata su Info o Verbose; in caso contrario, false
.
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.*/
private:
static TraceSwitch^ mySwitch = gcnew TraceSwitch( "General", "Entire Application" );
public:
static 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." );
}
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("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();
}
' Class-level declaration.
' Create a TraceSwitch to use in the entire application.
Private Shared mySwitch As New TraceSwitch("General", "Entire Application")
Public Shared Sub MyMethod()
' Write the message if the TraceSwitch level is set to Info or higher.
If mySwitch.TraceInfo 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
È 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.
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 |
Feedback su .NET
.NET è un progetto di open source. Selezionare un collegamento per fornire feedback: