Closed SanglierF closed 3 months ago
My mistake - appsettings were incorrectly formatted: Did it exactly like shown in serilog.sink.mssql and it works now.
"Name": "MSSqlServer",
"Args": {
"ConnectionString": "Data Source=(localdb)\\MSSQLLocalDB; Database=db_dev_logs;Trusted_Connection=True;",
"sinkOptionsSection": {
"AutoCreateSqlDatabase": "true",
"AutoCreateSqlTable": "true",
"SchemaName": "dbo",
"TableName": "LogEventsFrontend",
"outputTemplate": "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj} <s:{SourceContext}>{NewLine}{Exception}"
}
}
While using below code in Program.cs to use serilog, it doesn't want to create a database if it can't find one. And fails with:
Microsoft.Data.SqlClient.SqlException (0x80131904): Cannot open database "db_name_logs" requested by the login. The login failed.
But it works correctly when specifying AutoCreateSqlDatabase without using appsettings:
Appsettings file looks like this.
.Net Sdk - Version 8.0.5, released May 14, 2024 NuGet versions: Serilog - 3.1.1 Serilog.Sinks.MSSqlServer - 6.6.0 Serilog.Settings.Configuration - 8.0.0