Skip to content

Latest commit

 

History

History
68 lines (44 loc) · 2.34 KB

README.md

File metadata and controls

68 lines (44 loc) · 2.34 KB

Audit.NET.Channels

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

Store the audit events in memory in a bounded or unbounded Channel (System.Threading.Channels).

Audit events are produced to the channel for a consumer to retrieve.

Install

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

PM> Install-Package Audit.NET.Channels

NuGet Status NuGet Count

Usage

Please see the Audit.NET Readme

Configuration

Set the static Audit.Core.Configuration.DataProvider property to set the Channel data provider, or call the UseInMemoryChannel 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 ChannelDataProvider(Channel.CreateUnbounded<AuditEvent>());

Or by using the fluent configuration API:

Audit.Core.Configuration.Setup()
    .UseInMemoryChannelProvider(channel => channel.Bounded(100));

Provider Options

  • Bounded: Set the maximum number of events that the channel can hold. When the channel is full, the producer will be blocked until the consumer retrieves some events from the channel.
  • Unbounded: The channel can hold an unlimited number of events. The producer will never be blocked.

Consume events

The ChannelDataProvider allows to consume the events by providing a TakeAsync and TryTakeAsync methods.

For example:

// Start up
Audit.Core.Configuration.DataProvider = new ChannelDataProvider(c => c.Unbounded());

// Consumer
var dataProvider = Audit.Core.Configuration.DataProviderAs<ChannelDataProvider>();
while (!cancellationToken.IsCancellationRequested)
{
    var auditEvent = await dataProvider.TakeAsync(cancellationToken);

    // Handle the auditEvent...
    Handle(auditEvent);
}