Audit.NET.Kafka
April 9, 2025 ยท View on GitHub
Apache Kafka Server provider for Audit.NET library (An extensible framework to audit executing operations in .NET).
Send the audit events to an Apache Kafka topic.
Install
NuGet Package To install the package run the following command on the Package Manager Console:
PM> Install-Package Audit.NET.Kafka
Usage
Please see the Audit.NET Readme
Configuration
Set the static Audit.Core.Configuration.DataProvider property to set the Kafka data provider, or call the UseKafka 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 KafkaDataProvider(producerConfig)
{
TopicSelector = _ => "audit-topic"
};
Or by using the fluent configuration API:
Audit.Core.Configuration.Setup()
.UseKafka(_ => _
.ProducerConfig(producerConfig)
.Topic("audit-topic"));
If you want to use keyed messages
you have to use the generic KafkaDataProvider<TKey> and provide a way to obtain the key for each audit event:
Audit.Core.Configuration.Setup()
.UseKafka<string>(_ => _
.ProducerConfig(producerConfig)
.Topic("audit-topic")
.KeySelector(ev => ev.EventType));
Provider Options
- ProducerConfig: Instance of
ProducerConfigwith the producer configuration properties - Topic: The topic name to send the messages. Default is "audit-topic".
- TopicSelector: A function of the audit event that returns the topic name to use.
- PartitionSelector: (optional) A function of the audit event that returns the partition index to use.
- KeySelector: When using keyed messages, a function of the audit event that returns the key to use.
- HeadersSelector: Optional to use message headers. Configure the message headers to be used for a given audit event.
- KeySerializer: When using keyed messages to set a custom serializer for the key.
- AuditEventSerializer: Custom AuditEvent serializer. By default the audit event is JSON serialized + UTF8 encoded.
- ResultHandler: An action to be called for each kafka response.
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.

