serilog-mssql / serilog-sinks-mssqlserver

A Serilog sink that writes events to Microsoft SQL Server and Azure SQL
Apache License 2.0
278 stars 148 forks source link

Nothing logged if SqlAuthenticationProviders is configured for system.data.sqlclient #374

Closed Daniel-Svensson closed 1 year ago

Daniel-Svensson commented 2 years ago

Please clearly describe what the SQL Sink is doing incorrectly:

Nothing is logged. Selflog report a type initialization exception for Microsoft.data settings provider or similar and a message that a system.data type cannot be cast to the corresponding Microsoft.data type.

solution manually referring to Microsoft.data.sqlclient version 4 (or any release >= 2.1) solves the issue.

2.1 release notes: https://github.com/dotnet/SqlClient/blob/main/release-notes/2.1/2.1.0.md#sqlclientauthenticationproviders-configuration-section

Please clearly describe the expected behavior: Logs are sent to database

List the names and versions of all Serilog packages used in the project:

the connection string might need to contain any specific authentication mode such as "Active Directory Integrated", but I don't know for certain if that is required or not.

Target framework and operating system:

[ ] .NET Core 2.0 [X ] .NET Framework 4.8 (net 4.7.2 as well) [ ] .NET Framework 4.6.x [ ] .NET Framework 4.5.x OS:

Provide a simple reproduction of your Serilog configuration file, if any:

Provide a simple reproduction of your application code:

Copy code from https://devblogs.microsoft.com/dotnet/announcing-the-net-framework-4-7-2/#sql-azure-ad-universal-and-multi-factor-authentication-support or setup "SqlAuthenticationProviders" in app/web.config for system.data.sqlclient

Call test method and then setup the mssqlsink and log an event

Daniel-Svensson commented 2 years ago

Workaround: manually reference a later version of Microsoft.data.sqlclient such as 4.0 in the application solves the problem ( or downgrade the sink to 5.4)

ckadluba commented 1 year ago

We have now upgraded Microsoft.Data.SqlClient to version 5.0.1 and removed the sink native Azure Managed Identity support. This should fix this issue.