Audit trail abstractions for .NET — entity change tracking models, audit logging interfaces, and direct audit API. Zero infrastructure dependency for Application layer usage.
$ dotnet add package Clywell.Core.AuditAudit trail abstractions and EF Core implementation for .NET — entity change tracking, manual audit logging, and pluggable audit persistence.
dotnet add package Clywell.Core.Audit
For automatic EF Core change tracking:
dotnet add package Clywell.Core.Audit.EntityFramework
| Package | Description |
|---|---|
Clywell.Core.Audit | Audit abstractions — models, interfaces, and direct audit API. Zero infrastructure dependency. |
Clywell.Core.Audit.EntityFramework | EF Core implementation — automatic change tracking via SaveChangesInterceptor. |
services.AddAudit();
services.AddScoped<IAuditLogger, MyAuditLogger>();
Implement IAuditLogger to define where audit records are persisted:
public class MyAuditLogger : IAuditLogger
{
public Task LogAsync(IReadOnlyList<AuditEntry> entries, CancellationToken ct)
{
// Persist to database, queue, file, etc.
return Task.CompletedTask;
}
}
services.AddAudit(options =>
{
options.AuditOnly<Order>();
options.AuditOnly<Product>();
});
services.AddScoped<IAuditLogger, MyAuditLogger>();
services.AddAuditEntityFramework();
services.AddDbContext<AppDbContext>((sp, options) =>
{
options.UseSqlServer(connectionString)
.UseAuditInterceptor(sp);
});
IAuditLogger is required. Register your implementation in DI before writing audit records.SaveChangesAsync is required for EF interception. Synchronous SaveChanges() is intentionally not supported by AuditSaveChangesInterceptor.AddAuditEntityFramework() registers the interceptor; attach it to each DbContext with UseAuditInterceptor(sp).net10.0Microsoft.EntityFrameworkCoreUpdated actions, only properties that actually changed are recorded.IAuditLogger, IAuditUserProvider, and IAuditTimestampProvider per-invocation — safe for scoped dependencies.Created actions with identity columns, EntityId reflects the temporary key (e.g., "0") since interception occurs before the database assigns the final value.MIT — see LICENSE.