Closed chrisg920 closed 8 months ago
Hi @chrisg920!
Your config structure is wrong. The UseSqlBulkCopy
option is part of the MSSqlServerSinkOptions
object as documented here: https://github.com/serilog-mssql/serilog-sinks-mssqlserver?tab=readme-ov-file#usesqlbulkcopy.
Therefore your appsettings should look something like this.
"WriteTo": [
{
"Name": "MSSqlServer",
"Args": {
"connectionString": "<Removed>",
"restrictedToMinimumLevel": "Information",
"sinkOptionsSection": {
"tableName": "Jobs",
"schemaName": "Logging",
"autoCreateSqlTable": true,
"batchPostingLimit": 10,
"useSqlBulkCopy": false
}
}
}
Please refer to our sample apps for some inspiration: https://github.com/serilog-mssql/serilog-sinks-mssqlserver/blob/dev/sample/WorkerServiceDemo/appsettings.json.
Thanks for setting me straight on this. I was fooled by the fact that the other options worked just fine, but I think that was because they were part of the old configuration system and useSqlBulkCopy was not.
From: Christian Kadluba @.> Sent: Friday, March 15, 2024 7:35 AM To: serilog-mssql/serilog-sinks-mssqlserver @.> Cc: Glasser, Chris @.>; Mention @.> Subject: Re: [serilog-mssql/serilog-sinks-mssqlserver] UseSqlBulkCopy=false has no effect (Issue #526)
EXTERNAL SENDER
CAUTION: This email originated from outside your organization. Exercise caution when opening attachments or clicking links, especially from unknown senders.
Hi @chrisg920https://github.com/chrisg920!
Your config structure is wrong. The UseSqlBulkCopy option is part of the MSSqlServerSinkOptions object as documented here: https://github.com/serilog-mssql/serilog-sinks-mssqlserver?tab=readme-ov-file#usesqlbulkcopy.
Therefore your appsettings should look something like this.
"WriteTo": [
{
"Name": "MSSqlServer",
"Args": {
"connectionString": "<Removed>",
"restrictedToMinimumLevel": "Information",
"sinkOptionsSection": {
"tableName": "Jobs",
"schemaName": "Logging",
"autoCreateSqlTable": true,
"batchPostingLimit": 10,
"useSqlBulkCopy": false
}
}
}
Please refer to our sample apps for some inspiration: https://github.com/serilog-mssql/serilog-sinks-mssqlserver/blob/dev/sample/WorkerServiceDemo/appsettings.json.
— Reply to this email directly, view it on GitHubhttps://github.com/serilog-mssql/serilog-sinks-mssqlserver/issues/526#issuecomment-1999469640, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AR2UASM7QBRCWVNZHZJS3J3YYLME3AVCNFSM6AAAAABES3IXUWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSOJZGQ3DSNRUGA. You are receiving this because you were mentioned.Message ID: @.***> IMPORTANT NOTICES: This electronic transmission may contain confidential or privileged information. If you have received this message in error, please notify the sender by replying and delete the message without copying or disclosing it. If this email requests to transfer funds, DO NOT respond to this email and contact us immediately via known contact information.
Can you provide an XML config version of this, I tried:
<add key="serilog:write-to:MSSqlServer.sinkOptions:useSqlBulkCopy" value="false" />
and
<add key="serilog:write-to:MSSqlServer.sinkOptions:UseSqlBulkCopy" value="false" />
and
<add key="serilog:write-to:MSSqlServer.sinkOptions.useSqlBulkCopy" value="false" />
neither works and I don't see UseSqlBulkCopy in the example .configs
@dcanning Could you get the UseSqlBulkCopy option working for you or are you still facing this issue?
Bug Report / Support Request Template
If you are opening a feature request, you can ignore this template. Bug reports and requests for assistance usually require the same basic information described below. This will help us more quickly reproduce and investigate the problem you're reporting. (If you are using Serilog.Sinks.MSSqlServerCore, that package is deprecated, please switch to Serilog.Sinks.MSSqlServer before reporting an issue.)
Unable to write batch of 10 log events to the database due to the following error: System.InvalidOperationException: The given ColumnMapping does not match up with any column in the source or destination. at Microsoft.DataSqlClient.SqlBulkCopy.WriteToServerInternalRestContinuedAsync...
Since I did not have this problem when using AuditTo, I figured it must be as problem when using SqlBullkCopy indtead of using INSERT statements, so I decided to take advantage of the configuration setting for turning off SqlBulkCopy as I did not have time to troubleshoot the issue with bulk logging. This is what my configuration looks like:
After adding the useSqlBulkCopy setting, I still got the same error from above, telling me that it was still in fact using bulk copy instead of insert. I found that if I modified the code in SinkDependenciesFactory.Create to force it to use SqlInsertStatementWriter as follows:
it eliminated the error I was getting, telling me that it was now indeed not using bulk copy as I desired.
Note that all other settings work fine.
[X ] .NET 6 [ ] .NET Framework 4.8 [ ] .NET Framework 4.7 [ ] .NET Framework 4.6 OS: Windows 8.0