0

I have a category "MyCategory" and its AutoFlush property is true and Trace Listener is Flat File Trace Listener. I create a LogEntry and write it with category. Log will be written to file successfully.

If I change AutoFlush property to false and write a LogEntry, I can't understand why it's not written to file by LogSource. (when AutoFlush=false)

John Saunders
  • 160,644
  • 26
  • 247
  • 397
Leo Vo
  • 9,980
  • 9
  • 56
  • 78

1 Answers1

4

In streams a Flush() forces the stream to clear his buffer to the underlaying object. e.g. a file! So you logger will automatically flush, after every LogEntry, so you can see the result in file immediately.

The stream will clear his buffer when:

  • The buffer is full
  • The stream is disposing
  • ...

Addition:

LogSource keeps a list of LogEntries, with an Capacity of x. If the list of LogEntries > x => Write to File. That's the buffering with AutoFlush = false. It will only write, when the buffer is full, calling Flush or LogSource dispose.

AutoFlush = true; calls Flush() after every insert of LogEntry to force the writing to file. No buffering, if you want to call it so. That means, you will see every entry immediately, other then after x Entries.

John Saunders
  • 160,644
  • 26
  • 247
  • 397
Malmi
  • 387
  • 3
  • 8