Serilog ExpressionTemplate重命名日志级别并应用格式
我正在尝试使用serilog的expressionTemplate
并以以下方式写入日志级别:
{ "level": "INF", ... }
我知道如何使@l
qualt to last- 级别:@l <
:@l << /代码> 而且我知道如何将级别格式化为三个上案例字母 -
@l:u3
,但我无法将两者结合起来,但
我尝试了以下几个方面的尝试(尝试格式化模板时会失败例外):
level: @l:u3
{'level': @l:u3}
I'm trying to use serilog's ExpressionTemplate
and write the log level in the following way:
{ "level": "INF", ... }
I know how to alias @l
to level - level: @l
and I know how to format the level to three upper-case letters - @l:u3
but I'm unable to combine the two
I have tried the following without success (fails when trying to format the template with an exception):
level: @l:u3
{'level': @l:u3}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在写作时,这是 serilog.expressions 希望能尽快解决。
您可以通过有条件地解决它:
还有一些分支以用于剩余水平。
(另外,您可以写入和插入用户定义的功能沿
toshortlevel(@l)
的行,然后使用它。At the time of writing this is a limitation in Serilog.Expressions, which will hopefully be addressed soon.
You can work around it with conditionals:
With a few more branches for remaining levels.
(Alternatively, you could write and plug in a user defined function along the lines of
ToShortLevel(@l)
, and use that instead.)