Chad Jessup
Chad Jessup

Reputation: 620

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.

A simple example to show my current usage:

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

And what I see in CouchDB Futon: Test

My understanding is that LogContext will add a "Track" field with the value of "hi" to all Serilog logs until it's disposed. But, I'm not seeing that happening.

Upvotes: 1

Views: 297

Answers (1)

Chad Jessup
Chad Jessup

Reputation: 620

(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()

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

Upvotes: 2

Related Questions