How do I write a layout for NLog that outputs time with milliseconds like this 11:32:08:123
? I use ${date:format=yyyy-MM-dd HH\:mm\:ss}
but I need more time precision in my logs.
What is Nlog ? Nlog is an open source log platform. Through this platform, we can log an activity of an application. This makes an application's code easy to handle.
There is some small difference between NLog and log4net. NLog is easier to configure, and supports a much cleaner code-based configuration than log4net. I think the defaults in NLog are also more sensible than in log4net.
Layouts are defining the layout of the rendered output, examples are a CSV, JSON, XML (NLog 4.6+) or plain layout (the default). There are currently 5 layouts in NLog (including the default): https://nlog-project.org/config/?tab=layouts.
${date:format=yyyy-MM-dd HH\:mm\:ss.fff}
According to the NLog documentation, you can use C# DateTime format string.
This is a pretty good reference for DateTime format strings: http://www.geekzilla.co.uk/View00FF7904-B510-468C-A2C8-F859AA20581F.htm
${longdate}
Another alternative to the format suggested by harriyott is to use the ${longdate} renderer. It should automatically give you the precision you need.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With