TraceSwitch.TraceWarning Свойство

Определение

Получает значение, указывающее, активирует ли переключатель предупреждающие сообщения.

public:
 property bool TraceWarning { bool get(); };
public bool TraceWarning { get; }
member this.TraceWarning : bool
Public ReadOnly Property TraceWarning As Boolean

Значение свойства

Значение true, если для свойства Level задано значение Warning, Info или Verbose; в противном случае — значение false.

Примеры

В следующем примере кода создается новый TraceSwitch объект и параметр используется для определения того, следует ли выдавать сообщения об ошибках. Параметр создается на уровне класса. MyMethod записывает первое сообщение об ошибке, Level если свойство имеет значение TraceLevel.Warning или выше. Однако не записывает второе сообщение об ошибкеLevel, MyMethod если меньше 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 Warning or higher.
      if ( mySwitch->TraceWarning )
         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 Warning or higher.
    if (mySwitch.TraceWarning)
        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 Warning or higher.
    If mySwitch.TraceWarning 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

Комментарии

Свойства , , и можно использовать TraceErrorв сочетании с классами Debug и для Trace отправки всех сообщений с заданной важностью или выше.TraceVerboseTraceInfoTraceWarning Если свойству Level присвоено значение TraceLevel.Warning, создаются предупреждения и сообщения об обработке ошибок.

Применяется к

См. также раздел