AuditaX.SqlServer
1.0.2
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
The owner has unlisted this package.
This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
Requires NuGet 6.0 or higher.
dotnet add package AuditaX.SqlServer --version 1.0.2
NuGet\Install-Package AuditaX.SqlServer -Version 1.0.2
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.0.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AuditaX.SqlServer" Version="1.0.2" />
<PackageReference Include="AuditaX.SqlServer" />
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.0.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: AuditaX.SqlServer, 1.0.2"
#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.0.2
#: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.0.2
#tool nuget:?package=AuditaX.SqlServer&version=1.0.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
AuditaX.SqlServer
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 DATETIME2for timestampsIDENTITYcolumns 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"
}
}
Recommended Configuration for SQL Server
{
"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.SqlClientpackage (included as dependency)
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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net10.0
- AuditaX (>= 1.0.2)
- Microsoft.Data.SqlClient (>= 6.1.3)
- Microsoft.EntityFrameworkCore.SqlServer (>= 10.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
v1.0.2 - Compatibility updates for properties and related entities.