Store Audit.NET Trail Logs into Elasticsearch database
$ dotnet add package Audit.NET.ElasticsearchElasticsearch provider for Audit.NET library (An extensible framework to audit executing operations in .NET).
Store the audit events in Elasticsearch database using the Elastic.Clients.Elasticsearch library.
NuGet Package To install the package run the following command on the Package Manager Console:
PM> Install-Package Audit.NET.Elasticsearch
Please see the Audit.NET Readme
Set the static Audit.Core.Configuration.DataProvider property to set the Elasticsearch data provider, or call the UseElasticsearch
method on the fluent configuration. This should be done before any AuditScope creation, i.e. during application startup.
For example:
Audit.Core.Configuration.DataProvider = new ElasticsearchDataProvider()
{
ClientSettings = new ElasticsearchClientSettings(new Uri("http://localhost:9200")),
Index = new(ev => ev.EventType),
IdBuilder = ev => Guid.NewGuid()
};
Or by using the fluent configuration API:
Audit.Core.Configuration.Setup()
.UseElasticsearch(config => config
.Client(new ElasticsearchClient("<CLOUD ID>", new BasicAuthentication("user", "pass")))
.Index(auditEvent => auditEvent.EventType)
.Id(ev => Guid.NewGuid()));
Note that you can provide the settings as a function of the Audit Event.
Mandatory:
Optional:
This provider implements GetEvent and GetEventAsync methods to obtain an audit event by id:
var event = elasDataProvider.GetEvent(new ElasticsearchAuditEventId() { Index = "myindex", Id = "myid" });
Entity Framework Extensions and Dapper Plus are major sponsors and are proud to contribute to the development of Audit.NET
Combine the power of auditing with the speed of Bulk Operations to get the best of both worlds — audit and performance.