Reputation: 13
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.
Upvotes: 0
Views: 1221
Reputation: 19847
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
Upvotes: 3