Search code examples
.netloggingelasticsearchserilog

Serilog + serilog-sinks-elasticsearch +ElasticSearch Auth


I am far from being a Dev with any .net experience, but the dev team at work would like to use Serilog along with serilog-sinks-elasticsearch to push logs into my ELK stack.

Looking at the config for serilog-sinks-elasticsearch, there doesn't seem to be any way to send the creds require to write to the ElasticSearch Cluster.

Is this just a dumb ops person question or have I just missed the config somewhere?

Thanks


Solution

  • I struggled to find a good solution for this too. Adding the username/password to the url definitely does work but somehow doesnt feel right.

    This worked for me:

    .WriteTo.Elasticsearch(new ElasticsearchSinkOptions(new Uri("https://your-deployment.westeurope.azure.elastic-cloud.com:9243"))
    {
      ...,
      ModifyConnectionSettings = x => x.BasicAuthentication("elastic", "your-password"),
    })