Skip to content

Instantly share code, notes, and snippets.

@thepirat000
Created February 25, 2024 20:58
Show Gist options
  • Save thepirat000/3a6b1efc03eab3409e5b56053409648a to your computer and use it in GitHub Desktop.
Save thepirat000/3a6b1efc03eab3409e5b56053409648a to your computer and use it in GitHub Desktop.
InMemoryProducerDataProvider for Audit.NET
public class InMemoryProducerDataProvider : AuditDataProvider
{
private readonly BlockingCollection<AuditEvent> _events;
public int Count => _events.Count;
public InMemoryProducerDataProvider()
{
_events = new BlockingCollection<AuditEvent>();
}
public override object InsertEvent(AuditEvent auditEvent)
{
_events.Add(auditEvent);
return null;
}
public override Task<object> InsertEventAsync(AuditEvent auditEvent, CancellationToken cancellationToken = default)
{
_events.Add(auditEvent, cancellationToken);
return Task.FromResult<object>(null);
}
public override void ReplaceEvent(object eventId, AuditEvent auditEvent)
{
throw new NotImplementedException(ReplaceEventErrorString);
}
public override Task ReplaceEventAsync(object eventId, AuditEvent auditEvent, CancellationToken cancellationToken = default)
{
throw new NotImplementedException(ReplaceEventErrorString);
}
public AuditEvent Take(CancellationToken cancellationToken = default)
{
return _events.Take(cancellationToken);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment