serilog-contrib / Serilog.Sinks.Postgresql.Alternative

Serilog.Sinks.Postgresql.Alternative is a library to save logging information from https://github.com/serilog/serilog to https://www.postgresql.org/.
MIT License
67 stars 13 forks source link

HowTo: Change main properties column names #27

Closed David-Moreira closed 3 years ago

David-Moreira commented 3 years ago

Hello, First of all, thank you for keeping the support on this library. Can you change the main properties column names? message, message_template, timestamp, etc

I'd like to change the timestamp column name to created_on, is this possible? I tried smthg like, with no success: "loggerPropertyColumnOptions": { "created_on": { "Name": "Timestamp", "Format": "{0}", "WriteMethod": "Raw", "DbType": "Timestamp" }

SeppPenner commented 3 years ago

I guess, this should be possible, but I need to check it.

SeppPenner commented 3 years ago

I guess, you're configuring the sink via JSON? This should help you: https://github.com/SeppPenner/SerilogSinkForPostgreSQL/blob/master/HowToUse.md#configuration-via-json-file.

Just a small example that should solve your problem (You need to adjust your other settings like connection string, of course).

{
  "Serilog": {
    "WriteTo": [
      {
        "Name": "PostgreSQL",
        "Args": {
          "connectionString": "User ID=postgres;Password=postgres;Host=localhost;Port=5432;Database=Serilog;",
          "tableName": "TestLogs",
          "schemaName": null,
          "needAutoCreateTable": true,
          "loggerColumnOptions": {
            "Id": "IdAutoIncrement",
            "Message": "RenderedMessage",
            "MessageTemplate": "Message",
            "Level": "Level",
            "created_on": "Timestamp",
            "Exception": "Exception",
            "LogEvent": "LogEvent"
          }
        }
      }
    ]
  }
}
David-Moreira commented 3 years ago

@SeppPenner Thank you!