AuditaX.SqlServer 1.2.0

There is a newer version of this package available.
See the version list below for details.

Requires NuGet 6.0 or higher.

dotnet add package AuditaX.SqlServer --version 1.2.0
                    
NuGet\Install-Package AuditaX.SqlServer -Version 1.2.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.SqlServer" Version="1.2.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AuditaX.SqlServer" Version="1.2.0" />
                    
Directory.Packages.props
<PackageReference Include="AuditaX.SqlServer" />
                    
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.SqlServer --version 1.2.0
                    
#r "nuget: AuditaX.SqlServer, 1.2.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.SqlServer@1.2.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.SqlServer&version=1.2.0
                    
Install as a Cake Addin
#tool nuget:?package=AuditaX.SqlServer&version=1.2.0
                    
Install as a Cake Tool

AuditaX.SqlServer

NuGetLicense

SQL Server database provider for AuditaX audit logging library.

Installation

dotnet add package AuditaX
dotnet add package AuditaX.SqlServer
dotnet add package AuditaX.Dapper             # OR AuditaX.EntityFramework

Features

  • SQL Server-specific SQL query generation
  • Support for NVARCHAR(MAX) for change log storage
  • DATETIME2 for timestamps
  • IDENTITY columns for auto-increment
  • Compatible with SQL Server 2016+

Configuration

Service Registration

services.AddAuditaX(configuration)
    .UseDapper<DapperContext>()       // OR .UseEntityFramework<AppDbContext>()
    .UseSqlServer()                   // Add SQL Server provider
    .ValidateOnStartup();

Connection String

{
  "ConnectionStrings": {
    "DefaultConnection": "Data Source=localhost;Initial Catalog=MyDatabase;User ID=sa;Password=YourPassword;TrustServerCertificate=True"
  }
}
{
  "AuditaX": {
    "TableName": "AuditLog",
    "Schema": "dbo",
    "LogFormat": "Json",
    "AutoCreateTable": true,
    "EnableLogging": true
  }
}

Generated Table Schema

CREATE TABLE [dbo].[AuditLog] (
    [LogId] UNIQUEIDENTIFIER NOT NULL DEFAULT NEWSEQUENTIALID(),
    [SourceName] NVARCHAR(50) NOT NULL,
    [SourceKey] NVARCHAR(900) NOT NULL,
    [AuditLog] NVARCHAR(MAX) NOT NULL,  -- Use XML type for XML format
    CONSTRAINT [PK_AuditLog] PRIMARY KEY CLUSTERED ([LogId]),
    CONSTRAINT [UQ_AuditLog_Source] UNIQUE ([SourceName], [SourceKey])
);

CREATE INDEX IX_AuditLog_SourceName ON [dbo].[AuditLog] ([SourceName]) INCLUDE ([SourceKey]);
CREATE INDEX IX_AuditLog_SourceKey ON [dbo].[AuditLog] ([SourceKey]) INCLUDE ([SourceName]);

Querying Audit Logs

Basic Query

SELECT * FROM AuditLog
WHERE SourceName = 'Product';

Query JSON Changes

SELECT
    LogId,
    SourceName,
    SourceKey,
    JSON_VALUE(e.value, '$.action') AS EntryAction,
    JSON_VALUE(e.value, '$.user') AS EntryUser,
    JSON_VALUE(e.value, '$.timestamp') AS EntryTimestamp,
    JSON_VALUE(f.value, '$.name') AS FieldName,
    JSON_VALUE(f.value, '$.before') AS OldValue,
    JSON_VALUE(f.value, '$.after') AS NewValue
FROM AuditLog
CROSS APPLY OPENJSON(AuditLog, '$.auditLog') AS e
CROSS APPLY OPENJSON(e.value, '$.fields') AS f
WHERE JSON_VALUE(e.value, '$.action') = 'Updated';

Query XML Changes

SELECT
    LogId,
    SourceName,
    SourceKey,
    e.value('@Action', 'NVARCHAR(16)') AS EntryAction,
    e.value('@User', 'NVARCHAR(128)') AS EntryUser,
    e.value('@Timestamp', 'NVARCHAR(50)') AS EntryTimestamp,
    f.value('@Name', 'NVARCHAR(128)') AS FieldName,
    f.value('@Before', 'NVARCHAR(MAX)') AS OldValue,
    f.value('@After', 'NVARCHAR(MAX)') AS NewValue
FROM AuditLog
CROSS APPLY AuditLog.nodes('/AuditLog/Entry') AS t(e)
CROSS APPLY e.nodes('Field') AS u(f)
WHERE e.value('@Action', 'NVARCHAR(16)') = 'Updated';

DapperContext for SQL Server

using System.Data;
using Microsoft.Data.SqlClient;

public class DapperContext(IConfiguration configuration)
{
    private readonly string _connectionString = configuration.GetConnectionString("DefaultConnection")!;

    public IDbConnection CreateConnection() => new SqlConnection(_connectionString);
}

Requirements

  • SQL Server 2016 or later
  • Microsoft.Data.SqlClient package (included as dependency)

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.0.0 0 3/9/2026
1.2.4 29 3/9/2026
1.2.3 38 3/7/2026
1.2.2 170 3/3/2026
1.2.1 293 2/24/2026
1.2.0 272 2/24/2026
1.1.1 343 2/24/2026
1.1.0 354 2/21/2026
1.0.4 319 2/10/2026
1.0.3 597 12/17/2025

v1.1.0 - Added paged query results with TotalCount, parsed audit detail, and new IDatabaseProvider members for COUNT and paginated queries.