Search code examples
asp.net-coreelasticsearchserilogelkserilog-sinks-elasticsearch

How to change Serilog field name posted to Elastic Search


I have gotten my serilog elastic search sink working. My problem now is I am looking for a way to override or remove the default out of the box fields naming convention when logs are posted to elastic search.

Sample in my code.

Log.Information("{sTest} {sName} , "This is test.", "This is my name");

The one that will be created will have something like fields.sTest, fields.sName

Is there a way to ommit the "fields." prefix and just use the sTest and the sName? Thank you.


Solution

  • You need to set the InlineFields property to true.

    var loggerConfig = new LoggerConfiguration()
        .WriteTo.Elasticsearch(new ElasticsearchSinkOptions(new Uri("http://localhost:9200"))
        {
            InlineFields = true,
            ...
        });