Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
例如,我有 function doSomething(string a, string b, string c)。我想记录函数的执行。我想做这样的事情:
doSomething(string a, string b, string c)
Logger.Debug("Method doSomething executed", a, b, c)
避免在消息中写入参数,因为字符串可能很长。此功能类似于.Enrich.WithProperty("PropertyName", Value). 但我不能在 Logger 构造函数中执行此操作。记录写入SEQ.
.Enrich.WithProperty("PropertyName", Value)
SEQ
ForContext()可以这样做:
ForContext()
var enriched = Log.ForContext("A", a) .ForContext("B", b) .ForContext("C", c); enriched.Debug("Method doSomething executed");
通过记录的所有事件enriched都将具有属性A,B并C附加。
enriched
A
B
C