asp.net-coreelasticsearchserilogserilog-sinks-elasticsearch

Serilog Elasticsearch proxy in ASP.NET Core


I currently have a .NET console applications where I sink my logging to ELK using the partial complete method below:

private static LoggerConfiguration AddElasticSearch(this LoggerConfiguration config, IConfigurationRoot configuration,
     string keyIdentifier)
{
     var ignoreSslCerts = IgnoreRemoteServerCertificates(configuration);
     var elasticSearchUri = ElasticUrl(configuration);
     var elasticCredentials = ElasticBasicCredentials(configuration);

     if (string.IsNullOrEmpty(elasticSearchUri))
     {
         Console.WriteLine("Elastic search has not been configured - The elastic URL is null or empty");
         return config;
     }

     config.WriteTo.Elasticsearch(new ElasticsearchSinkOptions(new Uri(elasticSearchUri)) 
     ........
     .......
}

I would like to use a sink to batch the data to the web API and then send into ELK via a sink similar to below. I want to do this so that I do not need to generate API keys for ELK and the console applications do not need to know URL for elastic etc. Also if I want to change the logging system; I can just change it in one place on the backend.

I suppose I am trying to create a proxy into ELK using ASP.NET Core.

Anyone come across any examples of documents of doing this?

Thanks


Solution

  • The best way to do this is to use

    Serilog.Sinks.Http
    

    A good example or the question has been answered on the below links:

    Post Serilog logs to Rest api

    https://github.com/FantasticFiasco/serilog-sinks-http-sample-dotnet-core