Created
February 25, 2024 20:58
-
-
Save thepirat000/3a6b1efc03eab3409e5b56053409648a to your computer and use it in GitHub Desktop.
InMemoryProducerDataProvider for Audit.NET
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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