TraceSwitch.TraceError Свойство
Определение
Важно!
Некоторые сведения относятся к предварительной версии продукта, в которую до выпуска могут быть внесены существенные изменения. Майкрософт не предоставляет никаких гарантий, явных или подразумеваемых, относительно приведенных здесь сведений.
Получает значение, указывающее, активирует ли переключатель сообщения обработки ошибок.
public:
property bool TraceError { bool get(); };
public bool TraceError { get; }
member this.TraceError : bool
Public ReadOnly Property TraceError As Boolean
Значение свойства
Значение true
, если для свойства Level задано значение Error, Warning, Info или Verbose; в противном случае — значение false
.
Примеры
В следующем примере кода создается новый TraceSwitch объект и используется параметр, чтобы определить, следует ли выдавать сообщения об ошибках. Параметр создается на уровне класса. MyMethod
записывает первое сообщение об ошибке, если Level свойство имеет TraceLevel.Error значение или выше. Однако не записывает второе сообщение об ошибке, MyMethod
если значение Level меньше 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
Комментарии
Свойства , TraceWarningTraceInfoи TraceVerbose свойства можно использовать TraceErrorв сочетании с классами Debug и Trace для отправки всех сообщений с заданной важностью или больше. Level Если свойство имеет наивысшую важность, TraceLevel.ErrorError создаются только сообщения об обработке ошибок.