Question

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?
Was it helpful?

Solution

  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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top