次の方法で共有


TraceSwitch.TraceError プロパティ

スイッチがエラー処理メッセージを許可するかどうかを示す値を取得します。

名前空間: System.Diagnostics
アセンブリ: System (system.dll 内)

構文

'宣言
Public ReadOnly Property TraceError As Boolean
'使用
Dim instance As TraceSwitch
Dim value As Boolean

value = instance.TraceError
public bool TraceError { get; }
public:
property bool TraceError {
    bool get ();
}
/** @property */
public boolean get_TraceError ()
public function get TraceError () : boolean

プロパティ値

Level プロパティが TraceLevel.ErrorTraceLevel.WarningTraceLevel.Info、または TraceLevel.Verbose に設定されている場合は、true。それ以外の場合は false

解説

TraceErrorTraceWarningTraceInfo、および TraceVerbose の各プロパティを Debug クラスおよび Trace クラスと組み合わせて使用することによって、指定した重要度以上のすべてのメッセージを出力できます。Level プロパティを最も重要度の高い TraceLevel.Error (Error) に設定すると、エラー処理メッセージだけが出力されます。

使用例

新しい TraceSwitch を作成し、スイッチを使用してエラー メッセージを出力するかどうかを決定するコード例を次に示します。スイッチはクラス レベルで作成されます。MyMethod は、Level プロパティが TraceLevel.Error 以上に設定されている場合に最初のエラー メッセージを書き込みます。ただし、MyMethod は、LevelTraceLevel.Verbose 未満の場合は第 2 のエラー メッセージを書き込みません。

' 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
//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:
   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.
 */
private static TraceSwitch mySwitch =
    new TraceSwitch("General", "Entire Application");

public static void MyMethod()
{
    //Write the message if the TraceSwitch level is set to Error or higher.
    if (mySwitch.get_TraceError()) {
        Console.WriteLine("My error message.");
    }

    // Write the message if the TraceSwitch level is set to Verbose.
    if (mySwitch.get_TraceVerbose()) {
        Console.WriteLine("My second error message.");
    }
} //MyMethod

public static void main(String[] args)
{
    // Run the method that prints error messages based on the switch level.
    MyMethod();
} //main

プラットフォーム

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。

バージョン情報

.NET Framework

サポート対象 : 2.0、1.1、1.0

参照

関連項目

TraceSwitch クラス
TraceSwitch メンバ
System.Diagnostics 名前空間
TraceSwitch クラス
Switch クラス
TraceLevel 列挙体
Debug クラス
Trace クラス