How to understand about AutoFlush property of LogSource

梦想与她 提交于 2019-12-11 19:54:43

问题


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)


回答1:


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.



来源:https://stackoverflow.com/questions/9782946/how-to-understand-about-autoflush-property-of-logsource

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!