本文介绍了在NLog和/或Serilog中记录文字消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新:事实证明,这是Serilog(我将其传送到)中存在的差异,但在NLog中却不存在 ,后者将单个参数作为逐字字符串(作为一个(特别是,我可能会想到)

UPDATE: This turned out to be a discrepancy that exists in Serilog (which I tunnel to), but does not exist in NLog, which treats a single argument as a verbatim string (as one (and specifically, I) might expect)

使用NLog,如果我要记录可能包含嵌入式双括号的东西:{{而不折叠它们,最有效的方法是什么?

Using NLog, if I want to log something potentially containing embedded double braces: {{ without having them collapsed, what's the most efficient way?

例如:

NLog.LogManager.GetLogger("x").Warn("{{\"aaa}}")

在我的自定义serilog-target中出现:

emits in my custom serilog-target:

{"aaa}

我想要:

{{"aaa}}

NLog.LogManager.GetLogger("x").Warn("{0}","{{\"aaa}}")

最好的方法还是有更有效的方法?

the best way or is there a more efficient way ?

更新:无需此类技巧:

NLog.LogManager.GetLogger("x").Warn("{{\"aaa}}")

...确实可以正常工作!

... does indeed just work!

(这不是(仅仅是)我是个书呆子,它来自)

(This is not (just) me being pedantic, its a follow-on from a question regarding a high perf/throughput requirement)

推荐答案

原来的问题是错误的.上面的代码在NLog中有效-单个字符串不被视为消息模板,并且 逐字呈现.

Turns out the question is wrong. The code above works in NLog - a single string is not treated as a message template and is rendered verbatim.

每个链接的问题我都将其传送到Serilog,而Serilog正在崩溃,我在问题中展示了作用.

I was tunneling it thru to Serilog per the linked question, and Serilog was doing the collapsing I show the effects of in the question.

这篇关于在NLog和/或Serilog中记录文字消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 17:56