Lyo.Audit.Postgres 2.0.1

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

Lyo.Audit.Postgres

EF Core persistence for Lyo.Audit in PostgreSQL. Stores AuditChange and AuditEvent rows with JSONB columns for dictionary data.

Features

  • PostgresAuditRecorder. Implements IAuditRecorder and Lyo.Health.IHealth against PostgreSQL.
  • Migrations. EF Core migrations in the audit schema (PostgresAuditOptions.Schema) with audit_events and audit_changes tables.
  • Auto migrations. Optional startup migration when EnableAutoMigrations is on.

Examples

First steps

services.AddPostgresAuditRecorder(new PostgresAuditOptions {
    ConnectionString = configuration.GetConnectionString("Audit")!,
    EnableAutoMigrations = true
});

services.AddPostgresAuditRecorderFromConfiguration(configuration);

First steps (2)

services.AddAuditDbContextFactory(configuration.GetSection("PostgresAudit").Get<PostgresAuditOptions>()!);

Migrations

export AUDIT_CONNECTION_STRING="Host=localhost;Database=audit;Username=postgres;Password=postgres"
dotnet ef migrations add MigrationName --project Core/Audit/Lyo.Audit.Postgres

Registration

Extension What it adds
AddAuditDbContextFactory(options) / (Action<…>) Registers IDbContextFactory<AuditDbContext> and the migrations helper (AddPostgresMigrations).
AddAuditDbContextFactoryFromConfiguration(IConfiguration, …) Binds PostgresAuditOptions from "PostgresAudit" (override section via the optional configSectionName) and registers as above.
AddAuditDbContext(connectionString) Builds options from a raw connection string, registers the factory, and exposes a scoped AuditDbContext.
AddPostgresAuditRecorder(options) / (Action<…>) Calls AddAuditDbContextFactory and registers IAuditRecorderPostgresAuditRecorder as a singleton.
AddPostgresAuditRecorderFromConfiguration(IConfiguration, …) Same as the options overload, binding from configuration.

First steps

Need just the factory, for example to share with downstream services or run migrations yourself?

Health

HealthCheckName = "audit-postgres" comes from PostgresAuditRecorder implementing Lyo.Health.IHealth. The probe constructs an AuditDbContext and calls Database.CanConnectAsync. A failed connect is HealthResult.Unhealthy. Hosts resolving IEnumerable<IHealth> pick this recorder up.

Database schema

  • audit.audit_changes. id (uuid), timestamp, for_entity_type, for_entity_id (varchar), from_entity_type?, from_entity_id? (varchar), tenant_id? (uuid), old_values_json (jsonb), changed_properties_json (jsonb), created_timestamp, updated_timestamp?
  • audit.audit_events. id (uuid), event_type, timestamp, for_entity_type, for_entity_id (varchar), from_entity_type?, from_entity_id? (varchar), tenant_id? (uuid), message?, metadata_json? (jsonb), created_timestamp, updated_timestamp?

Tenancy

AuditEvent and AuditChange records carry an optional TenantId (mapped to the tenant_id column). Before persist, PostgresAuditRecorder runs every record through TenancyResolver.Resolve using the policy configured in PostgresAuditOptions.Tenancy (inheriting from EntityRefOptions.Mode when unset):

  • SystemOnly. Caller TenantId is ignored and the row stores null (system-level audit).
  • SingleTenantDefault (default). Caller value, falling back to Tenancy.DefaultTenantId then EntityRefOptions.DefaultTenantId.
  • MultiTenantStrict. Caller must supply a non-empty TenantId or persistence throws.

Each table has an ix_<table>_tenant index for filtered scans. Use WhereTenant(tenantId) to scope queries to a single tenant (or null for system rows) and WhereTenantOrSystem(tenantId) to include both. See Lyo.EntityReference.Postgres for the policy matrix.

{
  "PostgresAudit": {
    "ConnectionString": "Host=localhost;Database=audit;...",
    "Tenancy": { "Mode": "MultiTenantStrict" }
  }
}

Dependencies

Generated from ProjectReference / PackageReference (same model as docs/Lyo.ProjectGraph.html).

  • Lyo.Audit (direct, lyo)
  • Lyo.EntityReference.Postgres (direct, lyo)
  • Lyo.Exceptions (direct, lyo)
  • Lyo.Health (direct, lyo)
  • Lyo.Postgres (direct, lyo)
  • Lyo.Common.Core (transitive, lyo)
  • Lyo.EntityReference.Models (transitive, lyo)
  • Microsoft.Bcl.AsyncInterfaces 10.0.5 (transitive, microsoft, netstandard2.0)
  • Microsoft.EntityFrameworkCore 10.0.5 (transitive, microsoft)
  • Microsoft.EntityFrameworkCore.Design 10.0.5 (transitive, microsoft)
  • Microsoft.EntityFrameworkCore.Relational 10.0.5 (transitive, microsoft)
  • Microsoft.Extensions.DependencyInjection.Abstractions 10.0.5 (transitive, microsoft)
  • Microsoft.Extensions.Hosting.Abstractions 10.0.5 (transitive, microsoft)
  • Microsoft.Extensions.Options 10.0.5 (transitive, microsoft)
  • Microsoft.Extensions.Options.ConfigurationExtensions 10.0.5 (transitive, microsoft)
  • Npgsql.EntityFrameworkCore.PostgreSQL 10.0.3 (transitive, third-party)
  • System.Memory 4.6.3 (transitive, microsoft, netstandard2.0)
  • System.Text.Json 10.0.5 (transitive, microsoft, netstandard2.0)
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.1 63 9/14/2026
2.0.0 94 9/9/2026
1.0.13 97 8/25/2026
1.0.11 99 8/23/2026
1.0.9 105 8/22/2026
1.0.6 104 8/20/2026
1.0.4 95 8/20/2026
1.0.3 98 8/19/2026
1.0.2 98 8/19/2026
1.0.1 106 8/18/2026
1.0.0 106 8/16/2026