【问题标题】:Serilog's CouchDB sink doesn't seem to be using LogContextSerilog 的 CouchDB 接收器似乎没有使用 LogContext
【发布时间】:2015-02-05 17:23:44
【问题描述】:

我不确定如何将 Serilog 的 LogContext 与 CouchDB 接收器一起使用。

一个简单的例子来展示我目前的用法:

using (LogContext.PushProperty("Track", "hi"))
{
    this.Log.Information("test");
}

我在 CouchDB Futon 中看到的内容:

我的理解是,LogContext 会在所有 Serilog 日志中添加一个值为“hi”的“Track”字段,直到它被处理掉。但是,我没有看到这种情况发生。

【问题讨论】:

    标签: c# logging couchdb serilog


    【解决方案1】:

    (不知道如何回答我自己的问题,我通过进一步研究找到了解决方案。)

    为了像我一样使用 LogContext 类,记录器需要初始化: .Enrich.FromLogContext()

    我以为我已经做到了,但我……没有。

    this.Log = new LoggerConfiguration()
        .WriteTo.ColoredConsole()
        .WriteTo.CouchDB("http://127.0.0.1:5984/logs")
        .Enrich.FromLogContext()
        .CreateLogger();
    

    这解释在:https://github.com/serilog/serilog/wiki/Enrichment

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-01-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-26
      • 2022-09-26
      • 1970-01-01
      相关资源
      最近更新 更多