- Serilog: encapsulating Serilog.Sinks.Elasticsearch configuration
- Extension Methods: Log.Logger extension method for easy setup
public void ConfigureServices(IServiceCollection services)
{
Log.Logger = new LoggerConfiguration()
.ReadFrom.Configuration(Configuration)
.WriteToElasticsearchAws(Configuration);
}
Kibana is a great log aggrigation service, paired with AWS infrastructure it makes for an easy Logging As a Service experience. Serilog is an easy to implament and use logging diagnostics library, however, although there is a sink in place for Elasticsearch, it doesn't encapsulate the configuration needed for Elasticsearch in AWS.
In comes this NuGet package. 👏 👏
Written to allow setup via configuration you can now enjoy the benefits of Serilog, Elasticsearch, Kibana and AWS all together!
The default convention for configuration files is as below:
"ElasticsearchAwsConfiguration": {
"Region": "[AWS Region]<string>",
"IndexFormat": "[Index Format]<string>",
"InlineFields": false,
"MinimumLevel": "[Minimum Warning Level]<string>",
"Enabled": false,
"Url": "[Elasticsearch URL]<string>"
}
To ensure that your Access Key and Secret Key remain secret we reccomend storing these in a seperate config file to your standard application configuration.
"ElasticsearchAwsSecretsConfiguration": {
"AccessKey": "[AWS Access Key]<string>",
"SecretKey": "[AWS Secret Key]<string>"
}
Once your configuration is setup you need to register Elasticsearch with your applications logger:
public void ConfigureServices(IServiceCollection services)
{
Log.Logger = new LoggerConfiguration()
.ReadFrom.Configuration(Configuration)
.WriteToElasticsearchAws(Configuration);
}
Badda bing, badda boom, you have your logging working.
$ dotnet add package StockportGovUK.AspNetCore.Logging.Elasticsearch.Aws
If you have any suggestions, fixes or new features please reach out to us here on GitHub!