How to change Serilog field name posted to Elastic Search

891 views Asked by At

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.

1

There are 1 answers

0
Kahbazi On BEST ANSWER

You need to set the InlineFields property to true.

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