Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Writing to MS SQL #319

Open
buda56 opened this issue Jun 11, 2022 · 1 comment
Open

Writing to MS SQL #319

buda56 opened this issue Jun 11, 2022 · 1 comment

Comments

@buda56
Copy link

buda56 commented Jun 11, 2022

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
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants