Logging in DotNetCore with SeriLog and ElasticSearch

Logging is extremely important in business solutions. Without logging we don't know what's happing in the system. Therefor all programmers implement one of the popular logging frameworks and write their logging statements. In most of the cases these log statements ends up in a log file which resides in the application directory or a central location somewhere.


In case of errors in the system the support team has to find the location of the log files and check if there are errors in it. Most of the time the logging level has to be adjusted in order to get a right diagnosis.

Elastic search

The case that a support engineer has to find out the location of the logfiles and check if there are any errors can be avoided with ElasticSearch. Just write all you logfiles to ElasticSearch. Like this all your logs are in one centralized locaton. Second advantage is the big index of all Logs wich can be filtered on date and errors by component etc. Like this the errors will apear early on a dashboard and actions be be taken in an eary stage.


For this example SeriLog is used. Serilog configuration takes just one parameter: the url on which the Elastic Server is found.

            Log.Logger = new LoggerConfiguration()
                .Enrich.WithProperty("IP address", GetLocalIPAddress())
                .WriteTo.Elasticsearch(new ElasticsearchSinkOptions(new Uri("http://localhost:9200"))
                    AutoRegisterTemplate = true

This is enough to place your log in Elastic Search and read your logs with, for example, Kibana. 




Saving your comment....

Naam is verplicht!
Email is verplicht!
Opmerking is verplicht!