This repository was archived by the owner on Jun 1, 2024. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork194
Basic setup
Michiel van Oudheusden edited this pageApr 5, 2015 ·3 revisions
First make sure to install the package from nuget:
Install-Package serilog.sinks.elasticsearchThis will also install Serilog itself.
You will first need to create a logger. Normally you do this once at startup and place the logger inside your DI container.
varloggerConfig=newLoggerConfiguration().MinimumLevel.Debug().WriteTo.Elasticsearch(newElasticsearchSinkOptions(newUri("http://localhost:9200")){AutoRegisterTemplate=true,});varlogger=loggerConfig.CreateLogger();
The above code will register one sink, the Elasticsearch sink, with a reference to the ES server located on the localhost and port 9200. We also set the optionAutoRegisterTemplate to true. This will create the correct mapping for us at startup.
Next, we will write some events to Serilog.
logger.Error(newException("test"),"An error has occurred.");logger.Information("The {User} has just executed {Action}.","username","actionName");
This will write two events to Serilog which will deliver those to the registered sinks. In this case the Elasticsearch one and your two events will end up in Elasticsearch.