What's the meaning of the time stamp in nlog when async is on?

两盒软妹~` 提交于 2019-12-13 16:26:01

问题


I'm a little confused about NLog's behivor when I set async=true in NLog's configuration file.

  1. Is the timestamp in the log file present the time when logger.Debug/Error/Info/Trace is called, or is it the time that the log got written from buffer to file on the file system?
  2. Answer Nlog Async and Log Sequence mentioned that the order of the log sequence is not guaranteed when async is on, is that true?
  3. If I set async=true, does it has influence to the result when doing performance testing?

回答1:


  1. According to the NLog source: https://github.com/NLog/NLog/blob/master/src/NLog/Logger.cs the LogEventInfo objectc is created at the time of the logging call (and is timestamped at that point). The writing of the LogEventInfo object is then written, asynchronously, to the appropriate target(s). So, the timestamp in the logfile should represent the timestamp of the logging call itself, not the time of the logging info being written to the log file.

  2. I don't have anything to add to the linked answer. I will say that xharze is involved in NLog development, so he should know what he is talking about.

  3. My first guess is that setting async=true would improve performance of your application with respect to logging since the application would not have to wait for a logging request to complete before continuing execution.



来源:https://stackoverflow.com/questions/23149142/whats-the-meaning-of-the-time-stamp-in-nlog-when-async-is-on

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