简体   繁体   中英

NLOG real time logging

How to configure NLOG to have real time in log file? Real time I mean time when operation was executed (to be more precisely - when log method was called).

<target name="file" xsi:type="File"
        layout="${longdate}|${level:uppercase=true}|${logger}|${message}|${exception:format=toString}"
        fileName="D:/Logs/${shortdate}.log" />

{longdate} seems to be a writing to log file date/time.

When you call the Logger, then it will create a LogEventInfo-object that captures a timestamp.

log.Info("Hello World");   // Captures timestamp

When using the NLog Layout ${longdate} then it will output the original timestamp captured. Independent of how long it takes for the LogEventInfo to reach the final NLog target, then it will always print the captured timestamp.

Any issues you have with precision or delay is probably caused by the default time-source:

https://github.com/NLog/NLog/wiki/Time-Source

Any issues you have with performance of the NLog FileTarget can probably be fixed by using KeepFileOpen=true and ConcurrentWrites=false :

https://github.com/NLog/NLog/wiki/Performance

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM