ANJYR
ANJYR

Reputation: 2623

Add new column in Audit.WebAPI

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.

Upvotes: 1

Views: 482

Answers (1)

thepirat000
thepirat000

Reputation: 13114

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"));

Upvotes: 2

Related Questions