次の方法で共有


Trace.Write メソッド (Object)

オブジェクトの ToString メソッドの値を、 Listeners コレクションのトレース リスナに書き込みます。

<Conditional("TRACE")>
Overloads Public Shared Sub Write( _   ByVal value As Object _)
[C#]
[Conditional("TRACE")]
public static void Write(objectvalue);
[C++]
[Conditional("TRACE")]
public: static void Write(Object* value);
[JScript]
public
   Conditional("TRACE")
static function Write(value : Object);

パラメータ

解説

既定では、出力は DefaultTraceListener のインスタンスに書き込まれます。

このメソッドは、トレース リスナの Write メソッドを呼び出します。

使用例

generalSwitch という名前の TraceSwitch を作成する例を次に示します。このスイッチは、コード サンプルの外部で設定されています。

スイッチが TraceLevel Error 以上に設定されている場合、この例では value パラメータの最初の名前が Listeners に出力されます。 Listeners コレクションにリスナを追加する方法については、 TraceListenerCollection クラスのトピックを参照してください。

TraceLevel が Verbose に設定されている場合、この例では、最初のメッセージと同じ行にメッセージが表示されます。2 番目のメッセージの後に行終端記号が続きます。

 
' Class-level declaration.
' Create a TraceSwitch.
Private Shared generalSwitch As New TraceSwitch("General", "Entire Application")    

Public Shared Sub MyErrorMethod(myObject As Object)
    ' Write the message if the TraceSwitch level is set to Error or higher.
    If generalSwitch.TraceError Then
        Trace.Write(myObject)
    End If 
    ' Write a second message if the TraceSwitch level is set to Verbose.
    If generalSwitch.TraceVerbose Then
        Trace.WriteLine(" is not a valid value for this method.")
    End If
End Sub


[C#] 
// Class-level declaration.
 // Create a TraceSwitch.
 static TraceSwitch generalSwitch = new TraceSwitch("General", "Entire Application");
 
 static public void MyErrorMethod(Object myObject) {
    // Write the message if the TraceSwitch level is set to Error or higher.
    if(generalSwitch.TraceError)
       Trace.Write(myObject);
 
    // Write a second message if the TraceSwitch level is set to Verbose.
    if(generalSwitch.TraceVerbose)
       Trace.WriteLine(" is not a valid value for this method.");
 }


[C++] 
// Class-level declaration.
 // Create a TraceSwitch.
 static TraceSwitch* generalSwitch = new TraceSwitch(S"General", S"Entire Application");
 
public:
 static void MyErrorMethod(Object* myObject) {
    // Write the message if the TraceSwitch level is set to Error or higher.
    if(generalSwitch->TraceError)
       Trace::Write(myObject);
 
    // Write a second message if the TraceSwitch level is set to Verbose.
    if(generalSwitch->TraceVerbose)
       Trace::WriteLine(S" is not a valid value for this method.");
 }


[JScript] 
// Create a TraceSwitch.
var generalSwitch : TraceSwitch = new TraceSwitch("General", "Entire Application")    

function MyErrorMethod(errorObject : Object){
  // Write a message if the TraceSwitch level is set to Error or higher.
  if(generalSwitch.TraceError){
    Trace.Write(errorObject)

    // Write a second message if the TraceSwitch level is set to Verbose.
    if(generalSwitch.TraceVerbose)
      Trace.WriteLine(" is not a valid value for this method.")
    else
      Trace.WriteLine("")
  }
}

必要条件

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

参照

Trace クラス | Trace メンバ | System.Diagnostics 名前空間 | Trace.Write オーバーロードの一覧 | Debug | Trace | BooleanSwitch | TraceSwitch | TraceListener | DefaultTraceListener | ConditionalAttribute | ConditionalAttribute | ConditionalAttribute | ConditionalAttribute