gpt4 book ai didi

c# - 日志属性未记录在 Serilog 中

转载 作者:行者123 更新时间:2023-12-05 06:43:18 26 4
gpt4 key购买 nike

例如,我有函数doSomething(string a, string b, string c)。我想记录函数的执行。我想做这样的事情:

Logger.Debug("Method doSomething executed", a, b, c)

避免在消息中写入参数,因为字符串可能很长。此功能类似于 .Enrich.WithProperty("PropertyName", Value)。但我不能在 Logger 构造函数中执行此操作。日志写入 SEQ

最佳答案

ForContext() 可以这样做:

var enriched = Log.ForContext("A", a)
.ForContext("B", b)
.ForContext("C", c);

enriched.Debug("Method doSomething executed");

通过 enriched 记录的所有事件都将附加属性 ABC

关于c# - 日志属性未记录在 Serilog 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33892504/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com