Search code examples
c#.net-coreconfigurationserilog

Net Core 6.0 and Serilog: problem with configuration


I have a little problem with net core 6.0 and Serilog configuration.

When Serilog try to write into the DB, SQL Server get me the "login failed" error although login data are the same used by the application.

appsettings.json

{
  "ConnectionStrings": {
    "SqlServer": "Server=127.0.0.1,1433;Database=MyDb;User ID=MyUser;Password=MyPass;MultipleActiveResultSets=true;Max Pool Size=500;Persist Security Info=True;Encrypt=False;TrustServerCertificate=False;"
  },
  "AppSettings": {
  },
  "Logging": {
    "LogLevel": {
      "Default": "Debug",
      "Microsoft": "Warning",
      "Microsoft.Hosting.Lifetime": "Information"
    }
  },
  "Serilog": {
    "MinimumLevel": "Debug",
    "Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId", "WithExceptionDetails" ],
    "WriteTo": [
      {
        "Name": "MSSqlServer",
        "Args": {
          "connectionString": "Server=127.0.0.1,1433;Database=MyDb;User ID=MyUser;Password=MyPass;MultipleActiveResultSets=true;Max Pool Size=500;Persist Security Info=True;Encrypt=False;TrustServerCertificate=False;"
          "restrictedToMinimumLevel": "Information",
          "sinkOptionsSection": {
            "tableName": "Serilog",
            "schemaName": "dbo",
            "autoCreateSqlTable": false,
            "batchPostingLimit": 100
          },
          "columnOptionsSection": {
            "removeStandardColumns": [ "MessageTemplate" ],
            "additionalColumns": [
              {
                "ColumnName": "ApplicationName",
                "DataType": "nvarchar",
                "DataLength": 200,
                "AllowNull": true
              }
            ]
          }
        }
      }
    ],
    "Properties": {
      "ApplicationName": "SampleName"
    }
  },
  "AllowedHosts": "*"
}

Solution

  • Ok, I have found the solution. I think is a bug in the connection string parser: if i remove the port number, the sink runs correctly.