serilog/serilog-settings-configuration

Writing to MS SQL

buda56 opened this issue · 1 comments

Hi,
Can anyone shed some light on how to configure Serilog to work correctly with SQL and ASP.Net Core and Dot.Net 6, I have configured it correctly as far as I can see but it will not log to SQL, it logs okay to the console and to a log file. I have included my configuration below.

appsettings.json:

{
  "Serilog": {
    "Using": [ "Serilog.Sinks.Console", "Serilog.sinks.File", "Serilog.Sinks.MSSqlServer" ],
    "MinimumLevel": {
      "Default": "Information",
      "Override": {
        "Microsoft": "Warning",
        "Microsoft.Hosting.Lifetime": "Information"
      }
    },
    "WriteTo": [
      { "Name": "Console" },
      {
        "Name": "File",
        "Args": {
          "path": "./Logs/Log-.txt",
          "rollingInterval": "Day"
        }
      },
      { "Name": "MSSqlServer", "Args": { "connectionString": "Server=.;Database=RevIntra;Trusted_Connection=true;MultipleActiveResultSets=true", "tableName": "DBLogs", "autoCreateSqlTable": false}}
    ]
  }
}

Program.cs:

builder.Host.UseSerilog((ctx, lc) =>
    lc.ReadFrom.Configuration(ctx.Configuration));

app.UseSerilogRequestLogging();

Regards
Peter

You can add SelfLog.Enable(Console.Error) to debug issues during logging setup. Most probably this is some naming or file-not-found issue.