Serilog.Sinks.Postgresql.Alternative icon indicating copy to clipboard operation
Serilog.Sinks.Postgresql.Alternative copied to clipboard

Removing certain fields from LogEvent

Open tessierp opened this issue 2 years ago • 1 comments

I would like to know if there is a way to filter out certain fields from what is written in LogEvent. My current configuration is as follow


  {
	"Name": "PostgreSQL",
	"Args": {
	  "connectionString": "DevPostgreSQL",
	  "tableName": "Logs",
	  "schemaName": "log",
	  "needAutoCreateTable": true,
	  "needAutoCreateSchema": true,
	  "loggerColumnOptions": {
		"Id": "IdAutoIncrement",
		"Level": "LevelAsText",
		"TimeStamp": "Timestamp",
		"LogEvent": "LogEvent",
		"MessageTemplate": "Message"
	  },
	  "loggerPropertyColumnOptions": {
		"Application": {
		  "Name": "Application",
		  "Format": "{0}",
		  "WriteMethod": "Raw",
		  "DbType": "Text"
		},
		"LogType": {
		  "Name": "LogType",
		  "Format": "{0}",
		  "WriteMethod": "Raw",
		  "DbType": "Text"
		}
	  }
	}
  }

Which produces the current output in LogEvent :

{
  "Level": "Error",
  "Timestamp": "2023-03-24T12:25:31.3008171-04:00",
  "Properties": {
    "LogType": "Log",
    "Application": "WeatherApp",
    "ExceptionLog": {
      "StackTrace": "   at WebApplication1.Controllers.WeatherForecastController.Exception() in F:\\Users\\someone\\Projects\\Technology\\Coding\\DotNet\\MyProjects\\WebApplication1\\WebApplication1\\Controllers\\WeatherForecastController.cs:line 50",
      "ExceptionMessage": "Logging SystemException for testing purposes.",
      "InnerExceptionMessage": ""
    }
  },
  "MessageTemplate": "{@ExceptionLog}"
}

What I would like is to filter out everything except the content of the Message to produce something like this :

{
    "Properties": {
        "ExceptionLog": {
            "ExceptionMessage": "Logging SystemException for testing purposes.",
            "InnerExceptionMessage": "",
            "StackTrace": "   at WebApplication1.Controllers.WeatherForecastController.Exception() in F:\\Users\\someone\\Projects\\Technology\\Coding\\DotNet\\MyProjects\\WebApplication1\\WebApplication1\\Controllers\\WeatherForecastController.cs:line 50"
        }
    }
}

I was experimenting with the MSSQL Sink which is able to achieve this by configuring these parameters :

"logEvent": {
  "excludeAdditionalProperties": false,
  "excludeStandardColumns": false
},

Is there a way to achieve the same result with PostgreSQL Alternative's Sink? The reason is, all the data can be found in other columns and it would allow me to reduce the size of the data which could add up over time.

Thanks

tessierp avatar Mar 24 '23 16:03 tessierp