【问题标题】:Log properties not recording in Serilog未在 Serilog 中记录的日志属性
【发布时间】:2015-11-24 11:30:45
【问题描述】:

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

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

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

【问题讨论】:

    标签: c# logging serilog getseq


    【解决方案1】:

    ForContext() 可以这样做:

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

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

    【讨论】:

      猜你喜欢
      • 2020-10-28
      • 2022-09-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多