AuditaX.Dapper
2.4.0
Requires NuGet 6.0 or higher.
dotnet add package AuditaX.Dapper --version 2.4.0
NuGet\Install-Package AuditaX.Dapper -Version 2.4.0
<PackageReference Include="AuditaX.Dapper" Version="2.4.0" />
<PackageVersion Include="AuditaX.Dapper" Version="2.4.0" />
<PackageReference Include="AuditaX.Dapper" />
paket add AuditaX.Dapper --version 2.4.0
#r "nuget: AuditaX.Dapper, 2.4.0"
#:package AuditaX.Dapper@2.4.0
#addin nuget:?package=AuditaX.Dapper&version=2.4.0
#tool nuget:?package=AuditaX.Dapper&version=2.4.0
AuditaX.Dapper
Dapper ORM support for AuditaX audit logging library.
Installation
dotnet add package AuditaX
dotnet add package AuditaX.Dapper
dotnet add package AuditaX.SqlServer # or AuditaX.PostgreSql
Features
IAuditUnitOfWorkinterface for repository-level audit logging- Automatic change detection via reflection
- Works with any
DapperContextthat has aCreateConnection()method - Manual control over when audit logs are created
Configuration
appsettings.json
{
"AuditaX": {
"TableName": "AuditLog",
"Schema": "dbo",
"LogFormat": "Json",
"AutoCreateTable": true,
"EnableLogging": true,
"Entities": {
"Product": {
"SourceName": "Product",
"Key": "ProductId",
"Properties": [ "Name", "Price", "Stock" ]
}
}
}
}
Service Registration
services.AddAuditaX(configuration)
.UseDapper<DapperContext>()
.UseSqlServer() // or .UsePostgreSql()
.ValidateOnStartup();
Usage
Inject IAuditUnitOfWork into your repositories:
using AuditaX.Dapper.Interfaces;
public class ProductRepository(DapperContext context, IAuditUnitOfWork audit) : IProductRepository
{
public async Task<int> CreateAsync(Product product)
{
using var connection = context.CreateConnection();
// ... insert logic ...
await audit.LogCreateAsync(product);
return id;
}
public async Task<int> UpdateAsync(Product original, Product updated)
{
using var connection = context.CreateConnection();
// ... update logic ...
if (affected > 0)
{
await audit.LogUpdateAsync(original, updated);
}
return affected;
}
public async Task<bool> DeleteAsync(Product product)
{
using var connection = context.CreateConnection();
// ... delete logic ...
if (affected > 0)
{
await audit.LogDeleteAsync(product);
}
return affected > 0;
}
}
IAuditUnitOfWork Methods
| Method | Description |
|---|---|
LogCreateAsync<T>(T entity) |
Logs entity creation |
LogUpdateAsync<T>(T original, T modified) |
Logs entity update with field changes |
LogDeleteAsync<T>(T entity) |
Logs entity deletion |
How Change Detection Works
LogUpdateAsyncreceives original and modified entities- Uses reflection to compare configured
AuditableProperties - Uses
IChangeLogService.HasChanged()to detect differences - Only logs changes when values actually differ
- Serializes changes to JSON or XML based on configuration
DapperContext Requirements
Your DapperContext must have a public CreateConnection() method:
public class DapperContext(IConfiguration configuration)
{
private readonly string _connectionString = configuration.GetConnectionString("DefaultConnection")!;
public IDbConnection CreateConnection() => new SqlConnection(_connectionString);
}
Comparison with Entity Framework
| Feature | Dapper | Entity Framework |
|---|---|---|
| Change Tracking | Manual via IAuditUnitOfWork |
Automatic via interceptors |
| Audit Timing | Explicit calls in repository | On SaveChangesAsync() |
| Control | Full control over when to audit | Automatic for all changes |
Documentation
For complete documentation, see the main AuditaX repository.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. 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. |
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 2.4.0 | 286 | 5/29/2026 |
| 2.3.1 | 283 | 5/25/2026 |
| 2.3.0 | 266 | 5/25/2026 |
| 2.2.1 | 301 | 5/25/2026 |
| 2.2.0 | 305 | 5/20/2026 |
| 2.1.0 | 305 | 5/1/2026 |
| 2.0.0 | 440 | 3/9/2026 |
| 1.2.4 | 293 | 3/9/2026 |
| 1.2.3 | 299 | 3/7/2026 |
| 1.2.2 | 306 | 3/3/2026 |
| 1.2.1 | 316 | 2/24/2026 |
| 1.2.0 | 322 | 2/24/2026 |
| 1.1.1 | 320 | 2/24/2026 |
| 1.1.0 | 368 | 2/21/2026 |
| 1.0.4 | 350 | 2/10/2026 |
| 1.0.3 | 541 | 12/17/2025 |
2.4.0: DapperAuditUnitOfWork now resolves the configured WithReference selector and forwards it to IAuditService, so SourceReference (the human-readable entity name) is persisted for Dapper-tracked entities — previously it was always null. Requires AuditaX 2.4.0. 2.3.1: Republish bump aligned with AuditaX 2.3.1 (version-only). 2.3.0 introduced SourceReference widening to 512.