次の方法で共有


TraceSwitch.TraceInfo プロパティ

Level が Info または Verbose に設定されているかどうかを示す値を取得します。

Public ReadOnly Property TraceInfo As Boolean
[C#]
public bool TraceInfo {get;}
[C++]
public: __property bool get_TraceInfo();
[JScript]
public function get TraceInfo() : Boolean;

プロパティ値

Level が Info または Verbose に設定されている場合は true 。それ以外の場合は false

解説

TraceErrorTraceWarningTraceInfoTraceVerbose の各プロパティを Debug クラスおよび Trace クラスと組み合わせて使用することによって、指定した重要度以上のすべてのメッセージを出力できます。 LevelWarning に設定されているときは、情報メッセージ、警告、およびエラー処理メッセージが出力されます。

使用例

[Visual Basic, C#, C++] 新しい TraceSwitch を作成し、スイッチを使用してエラー メッセージを出力するかどうかを決定する例を次に示します。スイッチはクラス レベルで作成されます。 MyMethod は、 LevelTraceInfo 以上に設定されている場合に最初のエラー メッセージを書き込みます。しかし、 MyMethod は、 LevelTraceVerbose 未満の場合は第 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 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


[C#] 
//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();
 }
 

[C++] 
//Class-level declaration.
 /* Create a TraceSwitch to use in the entire application.*/
 static TraceSwitch* mySwitch = new TraceSwitch(S"General", S"Entire Application");
 
public:
 static void MyMethod() {
    // Write the message if the TraceSwitch level is set to Info or higher.
    if(mySwitch->TraceInfo)
       Console::WriteLine(S"My error message.");
 
    // Write the message if the TraceSwitch level is set to Verbose.
    if(mySwitch->TraceVerbose)
       Console::WriteLine(S"My second error message.");
 }
 
 static void main() {
    // Run the method that prints error messages based on the switch level.
    MyMethod();
 }
 

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

参照

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