AuditaX.PostgreSql 2.3.1

Requires NuGet 6.0 or higher.

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

AuditaX.PostgreSql

NuGetLicense

PostgreSQL database provider for AuditaX audit logging library.

Installation

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

Features

  • PostgreSQL-specific SQL query generation
  • Support for native JSONB type for JSON storage (efficient indexing and queries)
  • Native XML type for XML storage
  • TIMESTAMPTZ for timezone-aware timestamps
  • Snake_case naming convention support
  • Compatible with PostgreSQL 12+

Configuration

Service Registration

services.AddAuditaX(configuration)
    .UseDapper<DapperContext>()       // OR .UseEntityFramework<AppDbContext>()
    .UsePostgreSql()                  // Add PostgreSQL provider
    .ValidateOnStartup();

Connection String

{
  "ConnectionStrings": {
    "DefaultConnection": "Host=localhost;Database=mydatabase;Username=postgres;Password=YourPassword"
  }
}
{
  "AuditaX": {
    "TableName": "audit_log",
    "Schema": "public",
    "LogFormat": "Json",
    "AutoCreateTable": true,
    "EnableLogging": true
  }
}

Generated Table Schema

-- For JSON format (uses native JSONB type)
CREATE TABLE IF NOT EXISTS public.audit_log (
    log_id UUID NOT NULL DEFAULT gen_random_uuid(),
    source_name VARCHAR(64) NOT NULL,
    source_key VARCHAR(64) NOT NULL,
    audit_log JSONB NOT NULL,
    CONSTRAINT pk_audit_log PRIMARY KEY (log_id),
    CONSTRAINT uq_audit_log_source UNIQUE (source_name, source_key)
);

-- For XML format (uses native XML type)
CREATE TABLE IF NOT EXISTS public.audit_log (
    log_id UUID NOT NULL DEFAULT gen_random_uuid(),
    source_name VARCHAR(64) NOT NULL,
    source_key VARCHAR(64) NOT NULL,
    audit_log XML NOT NULL,
    CONSTRAINT pk_audit_log PRIMARY KEY (log_id),
    CONSTRAINT uq_audit_log_source UNIQUE (source_name, source_key)
);

CREATE INDEX IF NOT EXISTS ix_audit_log_source_name ON public.audit_log (source_name);
CREATE INDEX IF NOT EXISTS ix_audit_log_source_key ON public.audit_log (source_key);

Querying Audit Logs

Basic Query

SELECT * FROM audit_log
WHERE source_name = 'Product';

Query JSON Changes

SELECT
    log_id,
    source_name,
    source_key,
    entry->>'action' AS entry_action,
    entry->>'user' AS entry_user,
    entry->>'timestamp' AS entry_timestamp,
    field->>'name' AS field_name,
    field->>'before' AS old_value,
    field->>'after' AS new_value
FROM audit_log,
     jsonb_array_elements(audit_log->'auditLog') AS entry,
     jsonb_array_elements(entry->'fields') AS field
WHERE entry->>'action' = 'Updated';

Filter by Specific Field Change

-- Find all price changes (uses JSONB containment operator for efficient indexing)
SELECT * FROM audit_log
WHERE audit_log->'auditLog' @> '[{"fields": [{"name": "Price"}]}]';

Query XML Changes

SELECT
    log_id,
    source_name,
    source_key,
    unnest(xpath('//Entry/@Action', audit_log::xml))::text AS entry_action,
    unnest(xpath('//Entry/@User', audit_log::xml))::text AS entry_user,
    unnest(xpath('//Entry/@Timestamp', audit_log::xml))::text AS entry_timestamp,
    unnest(xpath('//Field/@Name', audit_log::xml))::text AS field_name,
    unnest(xpath('//Field/@Before', audit_log::xml))::text AS old_value,
    unnest(xpath('//Field/@After', audit_log::xml))::text AS new_value
FROM audit_log;

DapperContext for PostgreSQL

using System.Data;
using Npgsql;

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

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

Requirements

  • PostgreSQL 12 or later
  • Npgsql 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.3.1 265 5/25/2026
2.3.0 304 5/25/2026
2.2.1 311 5/25/2026
2.2.0 309 5/20/2026
2.1.0 320 5/1/2026
2.0.0 341 3/9/2026
1.2.4 309 3/9/2026
1.2.3 330 3/7/2026
1.2.2 327 3/3/2026
1.2.1 333 2/24/2026
1.2.0 314 2/24/2026
1.1.1 330 2/24/2026
1.1.0 381 2/21/2026
1.0.4 341 2/10/2026
1.0.3 504 12/17/2025

2.3.1: Republish bump of 2.3.0 (version-only change). Original 2.3.0: SourceReference column widened to VARCHAR(512). CreateTableSql and GetExpectedTableStructure updated. BREAKING: existing audit_log tables must ALTER source_reference to width >= 512.