NLog time formatting

时光毁灭记忆、已成空白 提交于 2019-12-04 15:00:11

问题


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.


回答1:


${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




回答2:


${longdate}

Another alternative to the format suggested by harriyott is to use the ${longdate} renderer. It should automatically give you the precision you need.




回答3:


Another alternative solution is to use the ISO 8601 format '1998-02-23T14:23:05.555'. This format is independet of the languange of the sql server.

${date:format=yyyy-MM-ddTHH\:mm\:ss.fff}


来源:https://stackoverflow.com/questions/3748740/nlog-time-formatting

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