NLog: Format loglevel with Whitespaces

最后都变了- 提交于 2019-12-03 06:28:53

Try using the PaddingLayoutRendererWrapper. I'm not sure where a good config example is, but the source in NLog's source repository is located here, so maybe you can reverse engineer the correct configuration:

https://github.com/NLog/NLog/blob/master/src/NLog/LayoutRenderers/Wrappers/PaddingLayoutRendererWrapper.cs

I think you would do something like this:

"${date:format=dd.MM.yyyy HH\\:mm\\:ss,fff} | ${padding:padding=5,fixedlength=true:${level:uppercase=true}} | ${message}"

Hopefully, that example will pad all log level values with 5 spaces on the left and then trim to an absolute length of 5.

padding=5 means to add 5 padcharacters (default is ' ') to left (negative means pad on right)

fixedlength=true is a boolean that indicates that the padded result should be trimmed to a maximum length of "padding" (i.e. 5 in my example)

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