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
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="AuditaX.Dapper" Version="2.4.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AuditaX.Dapper" Version="2.4.0" />
                    
Directory.Packages.props
<PackageReference Include="AuditaX.Dapper" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add AuditaX.Dapper --version 2.4.0
                    
#r "nuget: AuditaX.Dapper, 2.4.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package AuditaX.Dapper@2.4.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=AuditaX.Dapper&version=2.4.0
                    
Install as a Cake Addin
#tool nuget:?package=AuditaX.Dapper&version=2.4.0
                    
Install as a Cake Tool

AuditaX.Dapper

NuGetLicense

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

  • IAuditUnitOfWork interface for repository-level audit logging
  • Automatic change detection via reflection
  • Works with any DapperContext that has a CreateConnection() 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

  1. LogUpdateAsync receives original and modified entities
  2. Uses reflection to compare configured AuditableProperties
  3. Uses IChangeLogService.HasChanged() to detect differences
  4. Only logs changes when values actually differ
  5. 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.