Lyo.Audit.Postgres
1.0.1
dotnet add package Lyo.Audit.Postgres --version 1.0.1
NuGet\Install-Package Lyo.Audit.Postgres -Version 1.0.1
<PackageReference Include="Lyo.Audit.Postgres" Version="1.0.1" />
<PackageVersion Include="Lyo.Audit.Postgres" Version="1.0.1" />
<PackageReference Include="Lyo.Audit.Postgres" />
paket add Lyo.Audit.Postgres --version 1.0.1
#r "nuget: Lyo.Audit.Postgres, 1.0.1"
#:package Lyo.Audit.Postgres@1.0.1
#addin nuget:?package=Lyo.Audit.Postgres&version=1.0.1
#tool nuget:?package=Lyo.Audit.Postgres&version=1.0.1
Lyo.Audit.Postgres
PostgreSQL implementation of Lyo.Audit using Entity Framework Core. Persists AuditChange and AuditEvent records to PostgreSQL with JSONB columns for dictionary data.
Features
- PostgresAuditRecorder – Implements
IAuditRecorderandLyo.Health.IHealthwith PostgreSQL persistence - Migrations – EF Core migrations in the
auditschema (PostgresAuditOptions.Schema) withaudit_changesandaudit_eventstables - Auto migrations – Optional automatic migration on startup via
EnableAutoMigrations
Examples
Quick Start
services.AddPostgresAuditRecorder(new PostgresAuditOptions {
ConnectionString = configuration.GetConnectionString("Audit")!,
EnableAutoMigrations = true
});
services.AddPostgresAuditRecorderFromConfiguration(configuration);
Quick Start (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. |
AddAuditDbContext(Action<DbContextOptionsBuilder>) |
Uses a caller-provided DbContextOptionsBuilder (useful for tests or shared connection multiplexing). |
AddPostgresAuditRecorder(options) / (Action<…>) |
Calls AddAuditDbContextFactory and registers IAuditRecorder → PostgresAuditRecorder as a singleton. |
AddPostgresAuditRecorderFromConfiguration(IConfiguration, …) |
Same as the options overload, binding from configuration. |
Quick Start
Need just the factory (e.g. to share with downstream services or run migrations explicitly)?
Health
PostgresAuditRecorder implements Lyo.Health.IHealth with HealthCheckName = "audit-postgres". The probe opens an AuditDbContext and runs Database.CanConnectAsync, surfacing connection failures through HealthResult.Unhealthy so the recorder contributes to host health endpoints that resolve IEnumerable<IHealth>.
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
AuditChange and AuditEvent records carry an optional TenantId (mapped to the tenant_id column). PostgresAuditRecorder runs every record through
TenancyResolver.Resolve using the policy configured in PostgresAuditOptions.Tenancy (inheriting from EntityRefOptions.Mode when unset) before persisting:
SystemOnly— callerTenantIdis ignored and the row storesnull(system-level audit).SingleTenantDefault(default) — caller value, falling back toTenancy.DefaultTenantIdthenEntityRefOptions.DefaultTenantId.MultiTenantStrict— caller must supply a non-emptyTenantIdor 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)Microsoft.Extensions.Configuration.Binder10.0.5— (direct, microsoft)Lyo.Common— (transitive, lyo)Lyo.EntityReference.Models— (transitive, lyo)Microsoft.EntityFrameworkCore10.0.5— (transitive, microsoft)Microsoft.EntityFrameworkCore.Design10.0.5— (transitive, microsoft)Microsoft.EntityFrameworkCore.Relational10.0.5— (transitive, microsoft)Microsoft.Extensions.DependencyInjection.Abstractions10.0.5— (transitive, microsoft)Microsoft.Extensions.Hosting.Abstractions10.0.5— (transitive, microsoft)Microsoft.Extensions.Logging.Abstractions10.0.5— (transitive, microsoft)Microsoft.Extensions.Options10.0.5— (transitive, microsoft)Microsoft.Extensions.Options.ConfigurationExtensions10.0.5— (transitive, microsoft)Npgsql.EntityFrameworkCore.PostgreSQL10.0.3— (transitive, third-party)System.Memory4.6.3— (transitive, microsoft, netstandard2.0)System.Text.Json10.0.5— (transitive, microsoft, netstandard2.0)
| 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. |
-
net10.0
- Lyo.Audit (>= 1.0.1)
- Lyo.EntityReference.Postgres (>= 1.0.1)
- Lyo.Exceptions (>= 1.0.1)
- Lyo.Health (>= 1.0.1)
- Lyo.Postgres (>= 1.0.1)
- Microsoft.Extensions.Configuration.Binder (>= 10.0.5)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.