serilog / serilog-settings-configuration

A Serilog configuration provider that reads from Microsoft.Extensions.Configuration
Apache License 2.0
458 stars 130 forks source link

Writing to MS SQL #319

Open buda56 opened 2 years ago

buda56 commented 2 years ago

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

sungam3r commented 1 year ago

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