问题
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