Bium.Auditing.EntityFrameworkCore
1.0.0
See the version list below for details.
dotnet add package Bium.Auditing.EntityFrameworkCore --version 1.0.0
NuGet\Install-Package Bium.Auditing.EntityFrameworkCore -Version 1.0.0
<PackageReference Include="Bium.Auditing.EntityFrameworkCore" Version="1.0.0" />
<PackageVersion Include="Bium.Auditing.EntityFrameworkCore" Version="1.0.0" />
<PackageReference Include="Bium.Auditing.EntityFrameworkCore" />
paket add Bium.Auditing.EntityFrameworkCore --version 1.0.0
#r "nuget: Bium.Auditing.EntityFrameworkCore, 1.0.0"
#:package Bium.Auditing.EntityFrameworkCore@1.0.0
#addin nuget:?package=Bium.Auditing.EntityFrameworkCore&version=1.0.0
#tool nuget:?package=Bium.Auditing.EntityFrameworkCore&version=1.0.0
Bium.Auditing.EntityFrameworkCore

Bium.Auditing.EntityFrameworkCore
is a lightweight library that provides automatic auditing capabilities for Entity
Framework Core. It simplifies tracking creation, modification, and deletion information (including soft deletes) for
your entities. This package is ideal for applications where audit trails are required for data changes.
This package is designed to be used with a
SaveChangesInterceptor
to automatically apply auditing logic.
Features
DbContext Auditing Extensions (DbContextExtensions)
ApplyAuditing(dbContext)
Applies automatic auditing timestamps to all tracked entities without tracking the user.ApplyAuditing<TPrimaryKey>(dbContext, performedBy)
Applies auditing timestamps using the current UTC time and sets the user performing the operation.- The
performedBy
argument should be provided manually, retrieved fromHttpContextAccessor
, or obtained via a custom user service.
- The
ApplyAuditing<TPrimaryKey, TDateTime>(dbContext, performedBy, performedAt)
Applies auditing timestamps using a custom time (DateTime
orDateTimeOffset
) and sets the user performing the operation.- The
performedBy
argument should be provided manually, retrieved fromHttpContextAccessor
, or obtained via a custom user service. - The
performedAt
argument should be provided manually or via a custom datetime provider.
- The
Getting Started
ApplyAuditing
automatically applies audit information (creation, modification, deletion) to all entities implementing
IAuditKind
when SaveChanges
or SaveChangesAsync
is called. Using it with a SaveChangesInterceptor
ensures audit
trails are applied consistently without manually calling the methods in each repository or service.
Key Points
- Automatically sets creation time and creator ID for new entities.
- Automatically sets modification time and modifier ID for updated entities.
- Supports soft deletes: automatically sets deletion time and deleter ID without physically removing records.
- Easy integration with any
DbContext
.
Interceptor Examples
1. ApplyAuditing()
public class AuditingInterceptor : SaveChangesInterceptor
{
public override InterceptionResult<int> SavingChanges(DbContextEventData eventData, InterceptionResult<int> result)
{
if (eventData.Context != null)
eventData.Context.ApplyAuditing();
return base.SavingChanges(eventData, result);
}
public override ValueTask<InterceptionResult<int>> SavingChangesAsync(
DbContextEventData eventData,
InterceptionResult<int> result,
CancellationToken cancellationToken = default)
{
if (eventData.Context != null)
eventData.Context.ApplyAuditing();
return base.SavingChangesAsync(eventData, result, cancellationToken);
}
}
2. ApplyAuditing<TPrimaryKey>(dbContext, performedBy)
public class AuditingWithUserInterceptor : SaveChangesInterceptor
{
private readonly ICurrentUserService _currentUserService;
public AuditingWithUserInterceptor(ICurrentUserService currentUserService)
{
_currentUserService = currentUserService;
}
public override InterceptionResult<int> SavingChanges(DbContextEventData eventData, InterceptionResult<int> result)
{
if (eventData.Context != null)
eventData.Context.ApplyAuditing(_currentUserService.UserId);
return base.SavingChanges(eventData, result);
}
public override ValueTask<InterceptionResult<int>> SavingChangesAsync(
DbContextEventData eventData,
InterceptionResult<int> result,
CancellationToken cancellationToken = default)
{
if (eventData.Context != null)
eventData.Context.ApplyAuditing(_currentUserService.UserId);
return base.SavingChangesAsync(eventData, result, cancellationToken);
}
}
3. ApplyAuditing<TPrimaryKey, TDateTime>(dbContext, performedBy, performedAt)
public class AuditingWithUserAndTimeInterceptor : SaveChangesInterceptor
{
private readonly ICurrentUserService _currentUserService;
private readonly IDateTimeProvider _dateTimeProvider;
public AuditingWithUserAndTimeInterceptor(ICurrentUserService currentUserService, IDateTimeProvider dateTimeProvider)
{
_currentUserService = currentUserService;
_dateTimeProvider = dateTimeProvider;
}
public override InterceptionResult<int> SavingChanges(DbContextEventData eventData, InterceptionResult<int> result)
{
if (eventData.Context != null)
eventData.Context.ApplyAuditing(_currentUserService.UserId, _dateTimeProvider.UtcNow);
return base.SavingChanges(eventData, result);
}
public override ValueTask<InterceptionResult<int>> SavingChangesAsync(
DbContextEventData eventData,
InterceptionResult<int> result,
CancellationToken cancellationToken = default)
{
if (eventData.Context != null)
eventData.Context.ApplyAuditing(_currentUserService.UserId, _dateTimeProvider.UtcNow);
return base.SavingChangesAsync(eventData, result, cancellationToken);
}
}
Interceptor Usage
- No user tracking →
AuditingInterceptor
- Track user →
AuditingWithUserInterceptor
- Track user + custom timestamp →
AuditingWithUserAndTimeInterceptor
Make sure to register the interceptor as a scoped service and add it to your DbContext configuration.
Contributing
Contributions are welcome! Please follow the standard GitHub workflow:
- Fork the repository
- Create a new branch (
feature/your-feature
) - Commit your changes
- Open a pull request
License
Bium.Auditing.EntityFrameworkCore
is licensed under the MIT License.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net5.0
- Bium.Auditing.Contracts.Extensions (>= 1.0.0)
- Microsoft.EntityFrameworkCore (>= 5.0.17)
-
net6.0
- Bium.Auditing.Contracts.Extensions (>= 1.0.0)
- Microsoft.EntityFrameworkCore (>= 6.0.36)
-
net7.0
- Bium.Auditing.Contracts.Extensions (>= 1.0.0)
- Microsoft.EntityFrameworkCore (>= 7.0.20)
-
net8.0
- Bium.Auditing.Contracts.Extensions (>= 1.0.0)
- Microsoft.EntityFrameworkCore (>= 8.0.20)
-
net9.0
- Bium.Auditing.Contracts.Extensions (>= 1.0.0)
- Microsoft.EntityFrameworkCore (>= 9.0.9)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
- Initial Release