Data providers in Audit.NET define the storage mechanism for audit events. They implement a simple abstraction that controls where and how audit logs are persisted—whether to files, databases, cloud services, or other storage systems. This page provides an overview of the data provider concept, available implementations, and configuration approaches.
For detailed information about:
IAuditDataProvider interface and implementation patterns, see Data Provider ArchitectureA data provider (also called a storage sink) contains the logic to handle audit event output. When an AuditScope completes its lifecycle, the framework invokes the configured data provider to persist the AuditEvent data.
Core Lifecycle Integration
Sources: src/Audit.NET/AuditScope.cs254-293 src/Audit.NET/AuditScope.cs502-574
If no data provider is explicitly configured, Audit.NET defaults to FileDataProvider, which writes audit events as JSON files to the current working directory.
Sources: src/Audit.NET/Configuration.cs115-119 README.md636-638
Data providers implement the IAuditDataProvider interface with two primary methods:
InsertEvent: Stores a new audit event and returns a unique identifierReplaceEvent: Updates an existing event by its identifier (used with specific creation policies)Providers that support asynchronous operations also implement InsertEventAsync and ReplaceEventAsync. Providers that support event retrieval implement GetEvent and GetEventAsync.
Provider Interface Contract
Sources: README.md575-589
Data providers can be configured globally for the entire application or specified per individual audit scope.
Set the default provider using the Configuration.DataProvider property or the fluent API:
Configuration Flow
Sources: README.md639-679 src/Audit.NET/Configuration.cs32-46 src/Audit.NET/ConfigurationApi/Configurator.cs59-136
Override the global provider for specific audit scopes using AuditScopeOptions:
The framework resolves the data provider during scope creation, using the per-scope provider if specified, otherwise falling back to the global configuration.
Sources: README.md652-659 src/Audit.NET/AuditScope.cs26-79
Audit.NET includes data providers for various storage technologies, organized into the following categories:
| Category | Technology | Package | Fluent API Method |
|---|---|---|---|
| SQL | SQL Server | Audit.NET.SqlServer | .UseSqlServer() |
| MySQL | Audit.NET.MySql | .UseMySql() | |
| PostgreSQL | Audit.NET.PostgreSql | .UsePostgreSql() | |
| Entity Framework | Audit.EntityFramework | .UseEntityFramework() | |
| EF Core DbContext | Audit.EntityFramework.Core | .UseDbContext() | |
| NoSQL | MongoDB | Audit.NET.MongoDB | .UseMongoDB() |
| Azure Cosmos DB | Audit.NET.AzureCosmos | .UseAzureCosmos() | |
| Redis | Audit.NET.Redis | .UseRedis() | |
| Elasticsearch | Audit.NET.Elasticsearch | .UseElasticsearch() | |
| OpenSearch | Audit.NET.OpenSearch | .UseOpenSearch() | |
| DynamoDB | Audit.NET.DynamoDB | .UseDynamoDB() | |
| RavenDB | Audit.NET.RavenDB | .UseRavenDB() | |
| ImmuDB | Audit.NET.ImmuDB | .UseImmuDB() | |
| Firestore | Audit.NET.Firestore | .UseFirestore() | |
| Azure | Azure Blob Storage | Audit.NET.AzureStorageBlobs | .UseAzureBlob() |
| Azure Table Storage | Audit.NET.AzureStorageTables | .UseAzureTables() | |
| Azure Event Hubs | Audit.NET.AzureEventHubs | .UseAzureEventHubs() | |
| Messaging | Kafka | Audit.NET.Kafka | .UseKafka() |
| UDP Datagrams | Audit.NET.Udp | .UseUdp() | |
| .NET Channels | Audit.NET.Channels | .UseChannels() | |
| File/Logging | File System | Audit.NET (core) | .UseFileLogProvider() |
| Windows Event Log | Audit.NET.EventLog.Core | .UseEventLogProvider() | |
| Serilog | Audit.NET.Serilog | .UseSerilog() | |
| NLog | Audit.NET.NLog | .UseNLog() | |
| log4net | Audit.NET.log4net | .UseLog4net() | |
| Special | OpenTelemetry | Audit.NET (core) | .UseActivityProvider() |
| In-Memory | Audit.NET (core) | .UseInMemoryProvider() | |
| Null (no output) | Audit.NET (core) | .UseNullProvider() |
Sources: README.md767-804 src/pack.cmd1-114 src/push.cmd1-98
Audit.NET provides wrapper data providers that enhance or modify the behavior of other providers without changing the underlying storage logic:
Wrapper Provider Types
Wraps any data provider with Polly resilience strategies such as retry policies and circuit breakers:
Sources: README.md745-763
Defers provider instantiation until first use, useful when dependency resolution is needed but not immediately available:
Sources: README.md703-715 src/Audit.NET/ConfigurationApi/Configurator.cs68-72
Creates a new provider instance per audit event, allowing dynamic provider selection based on event data:
Sources: README.md717-730 src/Audit.NET/ConfigurationApi/Configurator.cs63-67
Routes events to different providers based on configurable conditions:
Sources: README.md732-743 src/Audit.NET/ConfigurationApi/Configurator.cs74-78
For detailed implementation patterns and advanced wrapper usage, see Wrapper Providers.
For scenarios requiring custom storage logic without creating a full provider class, Audit.NET offers dynamic providers:
Define insert and replace logic inline using delegates:
Similar to DynamicDataProvider but with asynchronous operations:
Sources: README.md686-701 test/Audit.UnitTest/UnitTest.cs224-241 test/Audit.UnitTest/UnitTest.Async.cs192-208
Refresh this wiki