Audit.NET.OpenSearch

April 9, 2025 ยท View on GitHub

OpenSearch provider for Audit.NET library (An extensible framework to audit executing operations in .NET).

Store the audit events in OpenSearch database using the OpenSearch.Client library.

Install

NuGet Package To install the package run the following command on the Package Manager Console:

PM> Install-Package Audit.NET.OpenSearch

NuGet Status NuGet Count

Usage

Please see the Audit.NET Readme

Configuration

Set the static Audit.Core.Configuration.DataProvider property to set the OpenSearch data provider, or call the UseOpenSearch 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 OpenSearchDataProvider()
{
    ClientSettings = new ConnectionSettings(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()
    .UseOpenSearch(config => config
        .Client(new OpenSearchClient("<CLOUD ID>", new BasicAuthenticationCredentials("user", "pass")));
        .Index(auditEvent => auditEvent.EventType)
        .Id(ev => Guid.NewGuid()));

Note that you can provide the settings as a function of the Audit Event.

Provider Options

Mandatory:

  • Client / ClientSettings: Specifies how to create the OpenSearch client. You can either pass an instance of the OpenSearchClient or provide the OpenSearchClientSettings.

Optional:

  • Index: The OpenSearch index name to use. Can be NULL to use the default index.
  • Id / IdBuilder: The id to use for the given audit event. Can be NULL to use an auto-generated id.

Query events

This provider implements GetEvent and GetEventAsync methods to obtain an audit event by id:

var event = openSearchDataProvider.GetEvent(new OpenSearchAuditEventId() { Index = "myindex", Id = "myid" });

ZZZ Projects - Sponsorship

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.

Entity Framework Extensions - Sponsor

Dapper Plus - Sponsor