Reputation: 15
In my ASP.NET Core 2.1 web API, I use Serilog with MSSqlServerSink. How can I alter the default table structure and add data to those columns by configuring it using appsettings?
I've tried settings the values as per the documentation examples but there are no errors. It is just as if the settings are ignored. I know the settings are being read because some of them are being picked up such as the table name. I've posted questions on other ASP.NET forums and the suggestions don't have any effect. I posted questions on the Serilog Gitter feed but I didn't get an answer. I did post on the github issues and someone suggested upgrading from the latest version to the dev version but this is a live environment. This is the section in the appsettings.json file that configures serilog.
"Serilog": {
"Using": [ "Serilog.Sinks.MSSqlServer" ],
"MinimumLevel": {
"Default": "Information",
"Override": {
"Microsoft": "Warning"
}
},
"WriteTo": [
{
"Name": "MSSqlServer",
"Args": {
"connectionString": "Server=(local);Database=ACLWebAPILogs;trusted_connection=true",
"tableName": "ACLWebAPILog",
"restrictedToMinimumLevel": "Information",
"autoCreateSqlTable": true
"columnOptionsSection": {
"disableTriggers": true,
"removeStandardColumns": [ "MessageTemplate", "Properties" ],
"additionalColumns": [
{
"ColumnName": "ControllerName",
"DataType": "nvarchar",
"AllowNull": true,
"DataLength": 50
},
{
"ColumnName": "MessageType",
"DataType": "nvarchar",
"AllowNull": true,
"DataLength": 50
}
]
}
}
}
]
}
The code that is in the Startup constructor in Startup.cs has the following line to add the logging system:
// Init Serilog configuration
Log.Logger = new LoggerConfiguration()
.ReadFrom.ConfigurationSection(configuration.GetSection("Serilog"))
.CreateLogger();
In the Configure function I do have:
loggerFactory.AddSerilog();
I would have expected this to have removed the MessageTemplate and Properties columns and added the two referenced below. It's as if everything passed autoCreateSqlTable is ignored. I've looked at Enrichers and they don't do what I want.
Upvotes: 0
Views: 1101
Reputation: 7865
Update Serilog.Sinks.MSSqlServer
to version 5.1.3
Install-Package Serilog.Sinks.MSSqlServer -Version 5.1.3
Check this answer for more details https://stackoverflow.com/a/55264488/3134112
Upvotes: 1