Closed kad1r closed 2 years ago
Hi I am facing same problem for Serilog.Sinks.MongoDB. I want to remove standard column like 'Properties' and add some custom columns. Below configuration is working for the SQL but its not working for Mongo DB.
App.Setting.json
{ "Serilog": { "Using": [ "Serilog.Sinks.MSSqlServer", "Serilog.Sinks.MongoDB" ], "MinimumLevel": "Debug", "WriteTo": [ "Console", { "Name": "MSSqlServer", "Args": { "connectionString": "Data Source=(LocalDB)\MSSQLLocalDB;Initial Catalog=SerilogTest;Integrated Security=True;", "tableName": "Logs", "autoCreateSqlTable": true, "columnOptionsSection": { "removeStandardColumns": [ "Properties" ], "customColumns": [ { "ColumnName": "EventType", "DataType": "int", "AllowNull": false }, { "ColumnName": "TestColumn", "DataType": "int", "AllowNull": false }, { "ColumnName": "Release", "DataType": "varchar", "DataLength": 32 } ] } } }, { "Name": "MongoDB", "Args": { "databaseUrl": "mongodb://localhost/logs", "collectionName": "Logs", "restrictedToMinimumLevel": "Information", "columnOptionsSection": { "removeStandardColumns": [ "Properties" ], "customColumns": [ { "ColumnName": "EventType", "DataType": "int" }, { "ColumnName": "TestColumn", "DataType": "int" }, { "ColumnName": "Release", "DataType": "string"
} ]
}
} } ]
} }
With the latest version, you can add the columns to the output for the logger for the MongoDBBson() sink (using a custom object for example):
Log.ForContext("MyCustomObject", new { Hi = 1, Custom = 2 }, true).Debug("Testing");
This outputs into the Mongo like so:
Let me know if this is still an issue @kad1r and @ammachado -- thanks.
Closing this due to inactivity.
Hello, I'm storing modifications on the records as a change logs on mongodb. I'm wondering if it's possible to add custom columns? Or I want to store my changes as a json object not string. Because I don't want to do json parse on string variable. It's available on sql server but I couldn't find any documentation on mongo side.
Thank you.