Trace.Flush メソッドとは? わかりやすく解説

Trace.Flush メソッド

出力バッファフラッシュし、バッファ内のデータListeners書き込みます

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

<ConditionalAttribute("TRACE")> _
Public Shared Sub Flush
Trace.Flush
[ConditionalAttribute("TRACE")] 
public static void Flush
 ()
[ConditionalAttribute(L"TRACE")] 
public:
static void Flush ()
/** @attribute ConditionalAttribute("TRACE") */ 
public static void Flush
 ()
ConditionalAttribute("TRACE") 
public static function Flush
 ()
解説解説

ストリームフラッシュしても、Flush または Close明示的に呼び出さない限り、そのストリームの基になるエンコーダフラッシュされません。AutoFlush を true設定すると、データバッファからストリームフラッシュされますが、エンコーダの状態はフラッシュされません。これにより、エンコーダの状態 (一部文字) を維持できるため、次のブロック文字正確にエンコードできるようになります。この動作は、一部文字エンコードするためにはエンコーダがあらかじめその文字隣接する文字受け取っておく必要がある UTF8 および UTF7 に対して有効です。

使用例使用例

myTextListener という名前の TextWriterTraceListener を作成する例を次に示しますmyTextListener は、myOutputWriter という名前の StreamWriter を使用してTestFile.txt というファイル書き込みます。この例では、ファイルストリーム、およびテキスト ライタ作成しテキストの 1 行をファイル書き込んでから、出力フラッシュして終了します

Public Shared Sub Main()
    ' Create a file for output named TestFile.txt.
    Dim myFileName As String
 = "TestFile.txt"
    If Not File.Exists(myFileName) Then
        Dim myFile As Stream = File.Create(myFileName)
        
        ' Assign output file to output stream.
        Dim myOutputWriter As StreamWriter
        myOutputWriter = File.AppendText(myFileName)
        
        ' Create a new text writer using the output stream, and 
        ' add it to the trace listeners. 
        Dim myTextListener As New
 TextWriterTraceListener(myOutputWriter)
        Trace.Listeners.Add(myTextListener)
        
        ' Write output to the file.
        Trace.WriteLine("Test output")
        
        ' Flush and close the output stream.
        Trace.Flush()
        Trace.Close()
    End If
End Sub

public static void Main(string[]
 args) {
    // Create a file for output named TestFile.txt.
    String myFileName = "TestFile.txt";
    if(!File.Exists(myFileName))
    {
       Stream myFile = File.Create(myFileName);
 
    // Assign output file to output stream.
    StreamWriter myOutputWriter;
    myOutputWriter = File.AppendText(myFileName);
 
    /* Create a new text writer using the output
 stream, and 
     * add it to the trace listeners. */
    TextWriterTraceListener myTextListener = new 
       TextWriterTraceListener(myOutputWriter);
    Trace.Listeners.Add(myTextListener);
 
    // Write output to the file.
    Trace.WriteLine("Test output");
 
    // Flush and close the output stream.
    Trace.Flush();
    Trace.Close();
   }
 }
 
int main()
{
   
   // Create a file for output named TestFile.txt.
   String^ myFileName = "TestFile.txt";
   if (  !File::Exists( myFileName ) )
   {
      Stream^ myFile = File::Create( myFileName );
      
      // Assign output file to output stream.
      StreamWriter^ myOutputWriter;
      myOutputWriter = File::AppendText( myFileName );
      
      /* Create a new text writer using the output
 stream, and 
            * add it to the trace listeners. */
      TextWriterTraceListener^ myTextListener = gcnew TextWriterTraceListener( myOutputWriter
 );
      Trace::Listeners->Add( myTextListener );
      
      // Write output to the file.
      Trace::WriteLine( "Test output" );
      
      // Flush and close the output stream.
      Trace::Flush();
      Trace::Close();
   }
}

public static void main(String[]
 args)
{
    // Create a file for output named TestFile.txt.
    String myFileName = "TestFile.txt";
    if (!(File.Exists(myFileName))) {
        Stream myFile = File.Create(myFileName);

        // Assign output file to output stream.
        StreamWriter myOutputWriter;
        myOutputWriter = File.AppendText(myFileName);

        /* Create a new text writer using the output
 stream, and 
         * add it to the trace listeners. 
         */
        TextWriterTraceListener myTextListener =
            new TextWriterTraceListener(myOutputWriter);
        Trace.get_Listeners().Add(myTextListener);

        // Write output to the file.
        Trace.WriteLine("Test output");

        // Flush and close the output stream.
        Trace.Flush();
        Trace.Close();
    }
} //main
// Open or create a file stream for output named TestFile.txt.
var myOutputWriter : FileStream = File.OpenWrite("TestFile.txt")

// Specify myOutputWriter as the Trace output stream by
// adding it to the trace listeners. 
Trace.Listeners.Add(new TextWriterTraceListener(myOutputWriter))

// Write output to the file.
Trace.WriteLine("Test output")

// Flush and close the output stream.
Trace.Flush()
Trace.Close()

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
Trace クラス
Trace メンバ
System.Diagnostics 名前空間
Debug クラス
Trace クラス
BooleanSwitch クラス
TraceSwitch
TraceListener
DefaultTraceListener クラス
ConditionalAttribute クラス



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「Trace.Flush メソッド」の関連用語

Trace.Flush メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



Trace.Flush メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS