简体   繁体   English

Serilog的CouchDB接收器似乎未使用LogContext

[英]Serilog's CouchDB sink doesn't seem to be using LogContext

I'm not sure how to use Serilog's LogContext with the CouchDB sink. 我不确定如何将Serilog的LogContext与CouchDB接收器一起使用。

A simple example to show my current usage: 一个简单的例子来说明我当前的用法:

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

And what I see in CouchDB Futon: 我在CouchDB Futon中看到的是: 测试

My understanding is that LogContext will add a "Track" field with the value of "hi" to all Serilog logs until it's disposed. 我的理解是,LogContext将在所有Seri​​log日志中添加一个值为“ hi”的“ Track”字段,直到将其处理掉为止。 But, I'm not seeing that happening. 但是,我没有看到这种情况。

(Not sure how to answer my own question, I found the solution with further research.) (不确定如何回答自己的问题,我通过进一步研究找到了解决方案。)

In order to use the LogContext class like I was, the logger needs to be initialized with: .Enrich.FromLogContext() 为了像以前一样使用LogContext类,需要使用以下方法初始化记录器: .Enrich.FromLogContext()

I thought I had done this, but I ...didn't. 我以为我已经做到了,但是……没有。

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

This is explained at: https://github.com/serilog/serilog/wiki/Enrichment 对此进行了解释: https : //github.com/serilog/serilog/wiki/Enrichment

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM