R8.EntityFrameworkCore.AuditProvider
1.0.5
See the version list below for details.
dotnet add package R8.EntityFrameworkCore.AuditProvider --version 1.0.5
NuGet\Install-Package R8.EntityFrameworkCore.AuditProvider -Version 1.0.5
<PackageReference Include="R8.EntityFrameworkCore.AuditProvider" Version="1.0.5" />
paket add R8.EntityFrameworkCore.AuditProvider --version 1.0.5
#r "nuget: R8.EntityFrameworkCore.AuditProvider, 1.0.5"
// Install R8.EntityFrameworkCore.AuditProvider as a Cake Addin #addin nuget:?package=R8.EntityFrameworkCore.AuditProvider&version=1.0.5 // Install R8.EntityFrameworkCore.AuditProvider as a Cake Tool #tool nuget:?package=R8.EntityFrameworkCore.AuditProvider&version=1.0.5
R8.EntityFrameworkCore.AuditProvider
A .NET package for Entity Framework, providing comprehensive change tracking with deep insights. Capture creation, updates, deletions, and restorations of entities, including property names, old and new values, stack traces, and user details, all neatly stored in an Audits column as JSON.
Seamless Entity Auditing: Easily integrate audit functionality into your Entity Framework applications, offering a complete audit trail enriched with stack traces and user information. Gain full visibility into entity lifecycle changes for compliance, debugging, and accountability.
Full Entity Lifecycle Visibility: Track and visualize the complete life cycle of your entities with detailed auditing. In addition to changes, this package records the stack trace of changes and user actions, enabling a deeper understanding of data evolution and robust audit trails.
Installation
Step 1:
// ... other services
// Add AuditProvider
services.AddEntityFrameworkAuditProvider(options =>
{
// Your options here (See Options section)
});
services.AddDbContext<YourDbContext>((serviceProvider, optionsBuilder) =>
{
// Your DbContext connection configuration here
...
// Add AuditProviderInterceptor
optionsBuilder.AddEntityFrameworkAuditProviderInterceptor(serviceProvider);
});
Step 2:
- Implement
IAuditable
(andIAuditableDelete
) in yourAggregate Auditable Entity
(Or you can implementIAuditable
/IAuditableDelete
in yourEntity
directly):- Example for
PostgreSQL
: AggregateAuditable.cs - Example for
Microsoft Sql Server
: AggregateAuditable.cs
- Example for
- then inherit your entity from
AggregateAuditable
:
public record YourEntity : AggregateAuditable
{
// Your entity properties
// ...
public string FirstName { get; set; }
[IgnoreAudit] // Ignore this property from audit
public string LastName { get; set; }
// ...
}
Deleted
andUnDeleted
flags would be stored, only ifIAuditableDelete
implemented.- Flags
Created
/Changed
cannot be done simultaneously withDeleted
/UnDeleted
.
Step 3:
Migrate your database.
Highly recommended to test it on a test database first, to avoid any data loss.
Options
EntityFrameworkAuditProviderOptions
:
Option | Type | Description | Default |
---|---|---|---|
JsonOptions |
System.Text.Json.JsonSerializerOptions |
Json serializer options to serialize and deserialize audits | An optimal setting |
MaxStoredAudits * |
int? |
Maximum number of audits to store in Audits column |
null |
UserProvider |
Func<IServiceProvider, EntityFrameworkAuditUser> |
User provider to get current user id | null |
- If the number of audits exceeds this number, the earliest audits (except
Created
) will be removed from the column. Ifnull
, all audits will be stored.
Output
Stored data in Audits
column will be like this:
[
{
"f": "0",
// Created
"dt": "2023-09-25T12:00:00.0000000+03:30",
},
{
"f": "1",
// Updated
"dt": "2023-09-25T12:00:00.0000000+03:30",
"c": [
{
"n": "Name",
// Name of the property
"_v": "OldName",
// Old value
"v": "NewName"
// New value
}
],
"u": {
"id": "1",
// The user id (if provided)
"ad": {
// The user additional info (if provided)
"Username": "Foo"
}
}
},
{
"f": "2",
// Deleted
"dt": "2023-09-25T12:00:00.0000000+03:30",
},
{
"f": "3",
// Restored/Undeleted
"dt": "2023-09-25T12:00:00.0000000+03:30",
}
]
🎆 Happy coding!
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | 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. |
-
net6.0
- Microsoft.EntityFrameworkCore.Relational (>= 6.0.26)
- R8.EntityFrameworkCore.AuditProvider.Abstractions (>= 1.0.5)
-
net7.0
- Microsoft.EntityFrameworkCore.Relational (>= 7.0.15)
- R8.EntityFrameworkCore.AuditProvider.Abstractions (>= 1.0.5)
-
net8.0
- Microsoft.EntityFrameworkCore.Relational (>= 8.0.1)
- R8.EntityFrameworkCore.AuditProvider.Abstractions (>= 1.0.5)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.