NLog:使用Whitespaces格式化日志级别 [英] NLog: Format loglevel with Whitespaces
问题描述
目前我的布局字符串是:
$ $ p $ $ $ $ date:format = dd.MM.yyyy HH\ \:mm \\:ss,fff} | $ {level:uppercase = true} | $ {message}
结果如下:
18.12.2013 11:23:14,834 | INFO |这是一个信息
18.12.2013 11:23:14,835 | TRACE |这是一个跟踪
现在我想要的是格式化$ level来填充空白所以它看起来像一个5字符的表。
我想要:
18.12.2013 11:23:14,834 | INFO |这是一个信息
18.12.2013 11:23:14,835 | TRACE |这是一个跟踪
我没有发现任何可悲的事情...任何人都可以帮忙吗?
非常感谢!
尝试使用PaddingLayoutRendererWrapper。我不确定哪里有一个好的配置示例,但是NLog的源代码库中的源代码位于此处,所以也许可以反向设计正确的配置:
我认为你可以这样做:
$ {date:format = dd.MM.yyyy HH \\:mm \\:ss,fff} | $ {padding:padding = 5,fixedlength = true:$ {level:uppercase = true}} | $ {message}
将在左侧填充5个空格的所有日志级别值,然后修剪为5的绝对长度。
padding = 5
表示将5个填充字符(默认为'
)添加到左侧(负数表示填充右侧)
fixedlength = true
是一个布尔值即表示填充后的结果应该被修剪到填充(即填充)的最大长度。 5在我的例子)
I am using NLog for logging. Currently my Layout-String is:
"${date:format=dd.MM.yyyy HH\\:mm\\:ss,fff} | ${level:uppercase=true} | ${message}"
This results in the following Logs:
18.12.2013 11:23:14,834 | INFO | this is an info
18.12.2013 11:23:14,835 | TRACE | this is a trace
What I want now is to format the "$level" to fill up with Whitespaces so that it looks like a table with 5 Characters.
I would like to have:
18.12.2013 11:23:14,834 | INFO | this is an info
18.12.2013 11:23:14,835 | TRACE | this is a trace
I didn't find anything sadly... Can anyone help?
Thanks a lot!
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:
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)
这篇关于NLog:使用Whitespaces格式化日志级别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!