TraceSwitch.TraceError Właściwość
Ważne
Niektóre informacje odnoszą się do produktu w wersji wstępnej, który może zostać znacząco zmodyfikowany przed wydaniem. Firma Microsoft nie udziela żadnych gwarancji, jawnych lub domniemanych, w odniesieniu do informacji podanych w tym miejscu.
Pobiera wartość wskazującą, czy przełącznik zezwala na komunikaty obsługujące błędy.
public:
property bool TraceError { bool get(); };
public bool TraceError { get; }
member this.TraceError : bool
Public ReadOnly Property TraceError As Boolean
true
jeśli właściwość jest ustawiona Level na Error, , InfoWarninglub Verbose; w przeciwnym razie , false
.
Poniższy przykład kodu tworzy nowy TraceSwitch i używa przełącznika w celu określenia, czy emitować komunikaty o błędach. Przełącznik jest tworzony na poziomie klasy.
MyMethod
zapisuje pierwszy komunikat o błędzie, jeśli właściwość jest ustawiona na TraceLevel.Error lub nowsząLevel. Nie zapisuje jednak drugiego komunikatu o błędzie, MyMethod
jeśli wartość Level jest mniejsza niż 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 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("General", "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("General", "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
Właściwości , , i można używać TraceErrorw połączeniu z klasami Debug iTrace, aby emitować wszystkie komunikaty o określonej ważności lub większej.TraceVerboseTraceInfoTraceWarning Level Gdy właściwość jest ustawiona na najwyższą ważność, TraceLevel.ErrorError emitowane są tylko komunikaty obsługujące błędy.
Produkt | Wersje |
---|---|
.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 |
Opinia o produkcie .NET
.NET to projekt typu open source. Wybierz link, aby przekazać opinię: