Serilog..MSSqlServer ColumnMapping issue

99 Views Asked by At

I'm trying to configure serilog on my asp.net core 6 webapp. Sinks Console and File are working fine. But, it's throwing exception for MSsqlserver- Unable to write batch of 1 log events to the database due to following error: System.InvalidOperationException: The given ColumnMapping does not match up with any column in the source or destination. at Microsoft.Data.SqlClient.SqlBulkCopy.AnalyzeTargetAndCreateUpdateBulkCommand(BulkCopySimpleResultSet internalResults)

My target Framework - >net 6.0 Serilog.Sinks.MSsQLSERVER version - 6.3.0

CREATE TABLE Logs (
    Id bigint IDENTITY(1,1) PRIMARY KEY,
    Message nvarchar(max) NOT NULL,
    MessageTemplate nvarchar(max) NOT NULL,
    Level nvarchar(128) NOT NULL,
    Timestamp datetimeoffset(7) NOT NULL,
    Exception nvarchar(max),
)  ````   {
                "Name": "MSSqlServer",
                "Args": {
                    "connectionString": "Server=localhost;Database=aaaa;Trusted_Connection=True;MultipleActiveResultSets=true;Encrypt=False",
                    "sinkOptions": {
                        "tableName": "Logs",
                        "columnOptionsSection": {
                            "removeStandardColumns": [ "Properties" ],
                            "columnOptions": [
                                {
                                    "ColumnName": "Message",
                                    "DataType": "NVARCHAR",
                                    "DataLength": -1,
                                    "AllowNull": false
                                },
                                {
                                    "ColumnName": "MessageTemplate",
                                    "DataType": "NVARCHAR",
                                    "DataLength": -1,
                                    "AllowNull": false
                                },
                                {
                                    "ColumnName": "Level",
                                    "DataType": "NVARCHAR",
                                    "DataLength": 128,
                                    "AllowNull": false
                                },
                                {
                                    "ColumnName": "Timestamp",
                                  "DataType": "datetimeoffset",
                                    "AllowNull": false
                                },
                                {
                                    "ColumnName": "Exception",
                                    "DataType": "NVARCHAR",
                                    "DataLength": -1,
                                    "AllowNull": true
                                }
                            ]
                        }
                    }
                }
            },`
0

There are 0 best solutions below