1

I am writing Audit Log into postgres database using .net core. I am following article Audit.WebAPI. everything working fine. log write properly in database. My requirement is pass some other information while logging into database, but i am not able to do that. Please help me.

Postgresql table:

CREATE TABLE log.auditlog
(
  id integer NOT NULL DEFAULT nextval('log.auditlog_id_seq'::regclass),
  inserted_date timestamp without time zone NOT NULL DEFAULT now(),
  updated_date timestamp without time zone NOT NULL DEFAULT now(),
  data jsonb NOT NULL,
  module character varying(100),
  CONSTRAINT auditlog_pkey PRIMARY KEY (id)
)

Here I add extra column name as module and want to set data into it.

.Net Core

Audit.Core.Configuration.DataProvider = new PostgreSqlDataProvider()
            {
                ConnectionString = "Server=localhost;Port=5432;User Id=postgres;Password=1234;Database=postgres;",//Local
                TableName = "auditlog",
                IdColumnName = "id",
                DataColumnName = "data",
                DataType = "JSONB",
                Schema = "log",
                LastUpdatedDateColumnName = "updated_date"
            };

Through .NET Core for audit logging any other suggesting will be good.

ArunPratap
  • 4,816
  • 7
  • 25
  • 43
ANJYR
  • 2,583
  • 6
  • 39
  • 60
  • The current version does not allow to set custom columns on the postgreSQL table, but I'll work on a new version that does. I guess will be similar to the [CustomColumns on Audit.SqlServer](https://github.com/thepirat000/Audit.NET/tree/master/src/Audit.NET.SqlServer#configuration), will that work for you? – thepirat000 Apr 10 '19 at 16:28

1 Answers1

2

Starting on version 14.2.2 you can now specify custom columns on your PostgreSQL table with the CustomColumn() fluent API:

Audit.Core.Configuration.Setup()
    .UsePostgreSql(config => config
        .ConnectionString("Server=localhost;Port=5432;User Id=postgres;Password=1234;Database=postgres;")
        .TableName("auditlog")
        .IdColumnName("id")
        .DataColumn("data", DataType.JSONB)
        .Schema("log")
        .LastUpdatedColumnName("updated_date")
        .CustomColumn("event_type", ev => ev.EventType)
        .CustomColumn("module", ev => "MyModule"));
thepirat000
  • 12,362
  • 4
  • 46
  • 72