You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何为NLog的MicrosoftConsoleLayout配置TimestampFormat?

修改NLog控制台日志布局添加时间戳

你只需要在${MicrosoftConsoleLayout}后通过冒号传递TimestampFormat参数,把${longdate}对应的格式字符串赋值给它即可。${longdate}的默认格式是yyyy-MM-dd HH:mm:ss.fffffff,修改后的配置如下:

<target xsi:type="Console" name="lifetimeConsole" layout="${MicrosoftConsoleLayout:TimestampFormat=yyyy-MM-dd HH:mm:ss.fffffff}" />

配置完成后,控制台日志就会带上和${longdate}格式一致的时间戳。如果后续需要调整时间戳样式,直接修改TimestampFormat后的格式字符串就行。

内容的提问来源于stack exchange,提问作者Dominique

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.14 22:15:59