如何了解LogSource的AutoFlush属性 [英] How to understand about AutoFlush property of LogSource

查看:240
本文介绍了如何了解LogSource的AutoFlush属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类别 MyCategory,其AutoFlush属性为true,而跟踪侦听器为平面文件跟踪侦听器。我创建一个LogEntry并将其写入类别。日志将成功写入文件。

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.

如果我将AutoFlush属性更改为false并编写了LogEntry,则我不明白为什么不将其写入文件LogSource。 (当AutoFlush = false时)

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)

推荐答案

在流中 Flush ()会强制流清除其对底层对象的缓冲区。例如一份文件!因此,记录器将在每个LogEntry之后自动刷新,因此您可以立即在文件中看到结果。

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:


  • 缓冲区已满

  • 流正在处理

  • ...

添加:

LogSource保留列表LogEntries的容量为 x 。如果LogEntries列表> x =>写入文件。这就是 AutoFlush = false 的缓冲。

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; 调用时,它将仅在缓冲区已满时写入数据。每次插入LogEntry都会强制 Flush()强制写入文件。如果要调用它,则不进行缓冲。这意味着,您将立即看到每个条目,而不是在 x 条目之后。

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.

这篇关于如何了解LogSource的AutoFlush属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆