Logging a literal message in NLog and/or Serilog

孤人 提交于 2020-01-16 13:18:19

问题


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)


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

e.g.:

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

emits in my custom serilog-target:

{"aaa}

And I want:

{{"aaa}}

Is

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

the best way or is there a more efficient way ?

UPDATE: no such tricks required:

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)


回答1:


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.

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.



来源:https://stackoverflow.com/questions/49678739/logging-a-literal-message-in-nlog-and-or-serilog

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