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
<PackageReference Include="Lyo.Audit.Postgres" Version="2.0.1" />
<PackageVersion Include="Lyo.Audit.Postgres" Version="2.0.1" />
<PackageReference Include="Lyo.Audit.Postgres" />
paket add Lyo.Audit.Postgres --version 2.0.1
#r "nuget: Lyo.Audit.Postgres, 2.0.1"
#:package Lyo.Audit.Postgres@2.0.1
#addin nuget:?package=Lyo.Audit.Postgres&version=2.0.1
#tool nuget:?package=Lyo.Audit.Postgres&version=2.0.1
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
IAuditRecorderandLyo.Health.IHealthagainst PostgreSQL. - Migrations. EF Core migrations in the
auditschema (PostgresAuditOptions.Schema) withaudit_eventsandaudit_changestables. - Auto migrations. Optional startup migration when
EnableAutoMigrationsis 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 IAuditRecorder → PostgresAuditRecorder 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. 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)Lyo.Common.Core(transitive, lyo)Lyo.EntityReference.Models(transitive, lyo)Microsoft.Bcl.AsyncInterfaces10.0.5(transitive, microsoft, netstandard2.0)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.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 (>= 2.0.0)
- Lyo.EntityReference.Postgres (>= 2.0.0)
- Lyo.Exceptions (>= 2.0.0)
- Lyo.Health (>= 2.0.0)
- Lyo.Postgres (>= 2.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.