Audit.NET.PostgreSql 31.0.2

Audit.NET.PostgreSql

PostgreSQL Server provider for Audit.NET library (An extensible framework to audit executing operations in .NET).

Store the audit events in a PostgreSQL Table, in JSON format.

Install

NuGet Package To install the package run the following command on the Package Manager Console:

PM> Install-Package Audit.NET.PostgreSql

NuGet Status NuGet Count

Usage

Please see the Audit.NET Readme

Configuration

Set the static Audit.Core.Configuration.DataProvider property to set the PostgreSQL data provider, or call the UsePostgreSql method on the fluent configuration. This should be done before any AuditScope creation, i.e. during application startup.

For example:

Audit.Core.Configuration.DataProvider = new PostgreSqlDataProvider()
{
    ConnectionString = "Server=127.0.0.1;Port=5432;User Id=admin;Password=admin;Database=postgres;",
    TableName = "event",
    IdColumnName = "id",
    DataColumnName = "data",
    DataType = "JSONB",
    LastUpdatedDateColumnName = "updated_date",
    CustomColumns = new List<CustomColumn>()
    {
        new CustomColumn("event_type", ev => ev.EventType),
        new CustomColumn("user", ev => ev.Environment.UserName),
    }
};

Or by using the fluent configuration API:

Audit.Core.Configuration.Setup()
    .UsePostgreSql(config => config
        .ConnectionString("Server=127.0.0.1;Port=5432;User Id=admin;Password=admin;Database=postgres;")
        .TableName("event")
        .IdColumnName("id")
        .DataColumn("data", DataType.JSONB)
        .LastUpdatedColumnName("updated_date")
        .CustomColumn("event_type", ev => ev.EventType)
        .CustomColumn("user", ev => ev.Environment.UserName));

Provider Options

Mandatory:

  • ConnectionString: The PostgreSQL Server connection string. Defaults is Server=127.0.0.1;Port=5432;User Id=postgres;Password=admin;Database=postgres;
  • TableName: The events table name. If not specified, the default table name is event.
  • DataColumnName: The column name of the event table where the JSON will be stored. Can be set to NULL to avoid including the JSON column. If not specified, the default column name is data.
  • IdColumnName: The column name of the event identifier (the primary key). If not specified, the default column name is id.

Optional:

  • Schema: The PostgreSQL schema to use.
  • DataType: The type of the data column that stores the events. Can be JSON, JSONP or STRING. (Default is JSON).
  • LastUpdatedDateColumnName: The datetime column name to update when replacing events.
  • CustomColumn: Additional columns to store information from the audit event. (optional)

Table constraints

  • The table must exists.
  • The table must have a single ID column (Unique or Primary key).
  • The type of the ID column must be convertible to STRING.

For example:

CREATE TABLE public.event
(
    id bigserial NOT NULL,
    inserted_date timestamp without time zone NOT NULL DEFAULT now(),
    updated_date timestamp without time zone NOT NULL DEFAULT now(),
    data jsonb NOT NULL,
    event_type varchar(50),
    user varchar(50) NULL,
    CONSTRAINT event_pkey PRIMARY KEY (id)
)
WITH (
    OIDS = FALSE
)
TABLESPACE pg_default;

Query events

This provider implements GetEvent and GetEventAsync methods to obtain an audit event by id:

var event = dataProvider.GetEvent(1000);

The Postgre SQL data provider also includes basic support for querying the events collection.

Use the EnumerateEvents() method on PostgreSqlDataProvider class to run SQL-like queries against the audit events. The EnumerateEvents() method accepts any valid Postgre WHERE clause as a parameter.

For example:

IEnumerable<AuditEvent> events = postgreDataProvider.EnumerateEvents(
       "data #> '{Environment,UserName}' = '\"John\"'");

Will return the events whose property Environment.UserName is equal to 'John'.

This post contains information about the query syntax supported by JSONP data type. And here is the PostgreSQL documentation about JSON operators.

For complex querying capabilities, you should use the npgsql driver or the Npgsql EntityFramework provider directly.

ZZZ Projects - Sponsorship

Entity Framework Extensions and Dapper Plus are major sponsors and are proud to contribute to the development of Audit.NET

Combine the power of auditing with the speed of Bulk Operations to get the best of both worlds — audit and performance.

Entity Framework Extensions - Sponsor

Dapper Plus - Sponsor

No packages depend on Audit.NET.PostgreSql.

.NET Framework 4.6.2

.NET 6.0

.NET Standard 2.0

.NET Standard 2.1

Version Downloads Last updated
32.0.0 1 01/20/2026
31.3.3 1 01/20/2026
31.3.2 3 01/10/2026
31.3.1 1 12/11/2025
31.3.0 2 12/11/2025
31.2.0 2 12/11/2025
31.1.0 2 12/11/2025
31.0.2 23 10/16/2025
31.0.1 13 09/09/2025
31.0.0 5 09/11/2025
30.1.3 5 09/11/2025
30.1.2 5 09/11/2025
30.1.1 4 09/11/2025
30.0.2 19 07/09/2025
30.0.1 7 06/25/2025
30.0.0 7 06/25/2025
29.0.1 14 05/13/2025
29.0.0 7 06/25/2025
28.0.0 7 06/25/2025
27.5.3 10 05/01/2025
27.5.2 7 06/25/2025
27.5.1 7 06/25/2025
27.5.0 8 03/17/2025
27.4.1 8 02/26/2025
27.4.0 8 02/26/2025
27.3.3 8 02/26/2025
27.3.2 7 02/26/2025
27.3.1 8 02/26/2025
27.3.0 8 02/26/2025
27.2.0 8 02/26/2025
27.1.1 8 02/26/2025
27.1.0 8 02/26/2025
27.0.3 8 02/26/2025
27.0.2 8 02/26/2025
27.0.1 8 02/26/2025
27.0.0 8 02/26/2025
26.0.1 8 02/26/2025
26.0.0 8 02/26/2025
25.0.7 8 02/26/2025
25.0.6 8 02/26/2025
25.0.5 8 02/26/2025
25.0.4 7 02/26/2025
25.0.3 8 02/26/2025
25.0.2 8 02/26/2025
25.0.1 8 02/26/2025
25.0.0 7 02/26/2025
24.0.1 8 02/26/2025
24.0.0 8 02/26/2025
23.0.0 8 02/26/2025
22.1.0 8 02/26/2025
22.0.2 8 02/26/2025
22.0.1 8 02/26/2025
22.0.0 8 02/26/2025
21.1.0 8 02/26/2025
21.0.4 8 02/26/2025
21.0.3 8 02/26/2025
21.0.2 7 02/26/2025
21.0.1 8 02/26/2025
21.0.0 8 02/26/2025
20.2.4 7 02/26/2025
20.2.3 8 02/26/2025
20.2.2 8 02/26/2025
20.2.1 8 02/26/2025
20.2.0 7 02/26/2025
20.1.6 38 09/14/2024
20.1.5 8 02/26/2025
20.1.4 8 02/26/2025
20.1.3 6 02/26/2025
20.1.2 8 02/26/2025
20.1.1 8 02/26/2025
20.1.0 8 02/26/2025
20.0.4 8 02/26/2025
20.0.3 7 02/26/2025
20.0.2 8 02/26/2025
20.0.1 9 02/26/2025
20.0.0 8 02/26/2025
19.4.1 8 02/26/2025
19.4.0 8 02/26/2025
19.3.0 8 02/26/2025
19.2.2 8 02/26/2025
19.2.1 8 02/26/2025
19.2.0 8 02/26/2025
19.1.4 8 02/26/2025
19.1.3 7 02/26/2025
19.1.2 8 02/26/2025
19.1.1 7 02/26/2025
19.1.0 8 02/26/2025
19.0.7 8 02/26/2025
19.0.6 8 02/26/2025
19.0.5 8 02/26/2025
19.0.4 8 02/26/2025
19.0.3 8 02/26/2025
19.0.2 8 02/26/2025
19.0.1 8 02/26/2025
19.0.0 8 02/26/2025
19.0.0-rc.net60.2 7 02/26/2025
19.0.0-rc.net60.1 8 02/26/2025
18.1.6 8 02/26/2025
18.1.5 8 02/26/2025
18.1.4 8 02/26/2025
18.1.3 8 02/26/2025
18.1.2 8 02/26/2025
18.1.1 7 02/26/2025
18.1.0 8 02/26/2025
18.0.1 8 02/26/2025
18.0.0 8 02/26/2025
17.0.8 8 02/26/2025
17.0.7 8 02/26/2025
17.0.6 7 02/26/2025
17.0.5 9 06/01/2021
17.0.4 13 05/11/2021
17.0.3 11 05/04/2021
17.0.2 9 04/25/2021
17.0.1 10 04/20/2021
17.0.0 16 03/29/2021
16.5.6 10 03/25/2021
16.5.5 11 03/23/2021
16.5.4 10 03/11/2021
16.5.3 10 03/01/2021
16.5.2 8 02/26/2025
16.5.1 8 02/26/2025
16.5.0 8 02/26/2025
16.4.5 8 02/26/2025
16.4.4 8 02/26/2025
16.4.3 8 02/26/2025
16.4.2 8 02/26/2025
16.4.1 8 02/26/2025
16.4.0 8 02/26/2025
16.3.3 8 02/26/2025
16.3.2 8 02/26/2025
16.3.1 8 02/26/2025
16.3.0 8 02/26/2025
16.2.1 8 02/26/2025
16.2.0 8 02/26/2025
16.1.5 8 02/26/2025
16.1.4 4 02/26/2025
16.1.3 7 02/26/2025
16.1.2 8 02/26/2025
16.1.1 8 02/26/2025
16.1.0 8 02/26/2025
16.0.3 8 02/26/2025
16.0.2 8 02/26/2025
16.0.1 8 02/26/2025
16.0.0 8 02/26/2025
15.3.0 8 02/26/2025
15.2.3 8 02/26/2025
15.2.2 8 02/26/2025
15.2.1 8 02/26/2025
15.2.0 8 02/26/2025
15.1.1 8 02/26/2025
15.1.0 8 02/26/2025
15.0.5 7 02/26/2025
15.0.4 8 02/26/2025
15.0.3 8 02/26/2025
15.0.2 8 02/26/2025
15.0.1 8 02/26/2025
15.0.0 7 02/26/2025
14.9.1 8 02/26/2025
14.9.0 8 02/26/2025
14.8.1 8 02/26/2025
14.8.0 8 02/26/2025
14.7.0 8 02/26/2025
14.6.6 8 02/26/2025
14.6.5 8 02/26/2025
14.6.4 8 02/26/2025
14.6.3 8 02/26/2025
14.6.2 8 02/26/2025
14.6.1 8 02/26/2025
14.6.0 8 02/26/2025
14.5.7 8 02/26/2025
14.5.6 8 02/26/2025
14.5.5 8 02/26/2025
14.5.4 8 02/26/2025
14.5.3 8 02/26/2025
14.5.2 8 02/26/2025
14.5.1 8 02/26/2025
14.5.0 8 02/26/2025
14.4.0 8 02/26/2025
14.3.4 8 02/26/2025
14.3.3 7 02/26/2025
14.3.2 8 02/26/2025
14.3.1 9 02/26/2025
14.3.0 8 02/26/2025
14.2.3 7 02/26/2025
14.2.2 8 02/26/2025
14.2.1 8 02/26/2025
14.2.0 8 02/26/2025
14.1.1 8 02/26/2025
14.1.0 8 02/26/2025
14.0.4 8 02/26/2025
14.0.3 8 02/26/2025
14.0.2 8 02/26/2025
14.0.1 8 02/26/2025
14.0.0 8 02/26/2025
13.3.0 8 02/26/2025
13.2.2 8 02/26/2025
13.2.1 8 02/26/2025
13.2.0 8 02/26/2025
13.1.5 7 02/26/2025
13.1.4 8 02/26/2025
13.1.3 9 02/26/2025
13.1.2 7 02/26/2025
13.1.1 8 02/26/2025
13.1.0 8 02/26/2025
13.0.0 8 02/26/2025
12.3.6 8 02/26/2025
12.3.5 8 02/26/2025
12.3.4 8 02/26/2025
12.3.3 8 02/26/2025
12.3.2 8 02/26/2025
12.3.1 8 02/26/2025
12.3.0 8 02/26/2025
12.2.2 7 02/26/2025
12.2.1 8 02/26/2025
12.2.0 8 02/26/2025
12.1.11 8 02/26/2025
12.1.10 8 02/26/2025
12.1.9 8 02/26/2025
12.1.8 8 02/26/2025
12.1.7 8 02/26/2025
12.1.6 8 02/26/2025
12.1.5 8 02/26/2025
12.1.4 8 02/26/2025
12.1.3 8 02/26/2025
12.1.2 8 02/26/2025
12.1.1 8 02/26/2025
12.1.0 8 02/26/2025
12.0.7 8 02/26/2025
12.0.6 8 02/26/2025
12.0.5 8 02/26/2025
12.0.4 8 02/26/2025
12.0.3 7 02/26/2025
12.0.2 8 02/26/2025
12.0.1 8 02/26/2025
12.0.0 8 02/26/2025
11.2.0 8 02/26/2025
11.1.0 8 02/26/2025
11.0.8 8 02/26/2025
11.0.7 7 02/26/2025
11.0.6 8 02/26/2025
11.0.5 8 02/26/2025
11.0.4 8 02/26/2025
11.0.3 8 02/26/2025
11.0.2 8 02/26/2025
11.0.1 8 02/26/2025
11.0.0 8 02/26/2025
10.0.3 8 02/26/2025
10.0.2 8 02/26/2025
10.0.1 8 02/26/2025
10.0.0 8 02/26/2025
9.3.0 7 02/26/2025
9.2.0 8 02/26/2025
9.1.3 8 02/26/2025
9.1.2 7 02/26/2025
9.1.1 8 02/26/2025
9.1.0 8 02/26/2025
9.0.1 8 02/26/2025
9.0.0 8 02/26/2025
8.7.0 8 02/26/2025
8.6.0 8 02/26/2025
8.5.0 8 02/26/2025
8.4.0 8 02/26/2025