serilog-mssql / serilog-sinks-mssqlserver

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

After adding Serilog.Sinks.MSSqlServer to project has Microsoft.Data.SqlClient.SqlException #472

Closed andreyshiryaev closed 1 year ago

andreyshiryaev commented 1 year ago

Hi, I try to use Serilog.Sinks.MSSqlServer in .NET 6 and after adding the code below my project has the error

Serilog.Debugging.SelfLog.Enable(
      msg =>
      {
          System.Diagnostics.Trace.WriteLine(msg);
      }
      );

var sinkOpts = new MSSqlServerSinkOptions
{
    TableName = "Log",
    AutoCreateSqlDatabase = true,
};

var columnOpts = new ColumnOptions();

string constring = builder.Configuration.GetConnectionString("ImdbSqlConnection");
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.WriteTo.Console(theme: SystemConsoleTheme.Literate)
                .WriteTo.MSSqlServer(
                       connectionString: constring,
                       sinkOptions: sinkOpts,
                       columnOptions: columnOpts,
                       appConfiguration: builder.Configuration,
                       restrictedToMinimumLevel: Serilog.Events.LogEventLevel.Error)
                .CreateLogger();
builder.Host.UseSerilog();

I have the next error:

Unable to create database movies due to following error: Microsoft.Data.SqlClient.SqlException (0x80131904): A connection was successfully established with the server, but then an error occurred during the login process. (provider: SSL Provider, error: 0

When I delete Serilog.Sinks.MSSqlServer my project works fine and I have a correct database connection

As soon as I am adding Serilog.Sinks.MSSqlServer my project does not work even without using WriteTo.MSSqlServer(

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

I have

 <PackageReference Include="Serilog" Version="2.12.0" />
    <PackageReference Include="Serilog.Extensions.Hosting" Version="5.0.1" />
    <PackageReference Include="Serilog.Settings.Configuration" Version="3.4.0" />
    <PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
    <PackageReference Include="Serilog.Sinks.Elasticsearch" Version="9.0.0" />
    <PackageReference Include="Serilog.Sinks.MSSqlServer" Version="6.3.0" />

Target framework and operating system:

[ ] .NET 6

ckadluba commented 1 year ago

Hi @andreyshiryaev!

The problem your are facing is due to a breaking change in SqlClient 4 and we have covered it in our doc.

https://github.com/serilog-mssql/serilog-sinks-mssqlserver#release-600

Of course we always recommend proper encryption with a valid server cert but there is a also workaround if this is not possible.

Best regards, Christian