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

Pull Configuration from appsettings.json #12

Open
mrUlrik opened this issue Apr 24, 2019 · 1 comment
Open

Pull Configuration from appsettings.json #12

mrUlrik opened this issue Apr 24, 2019 · 1 comment

Comments

@mrUlrik
Copy link

mrUlrik commented Apr 24, 2019

I am pulling Serilog into the application via WebHostBuilder as documented here: https://github.com/serilog/serilog-aspnetcore#inline-initialization

This does not appear to load the connection string or the table name from the appsettings.json file, however it is using this file to pick up the Using: Serilog.Sinks.MySQL line.

{
  "Serilog": {
    "Using": [ "Serilog.Sinks.MySQL" ], 
    "LevelSwitches": { "$controlSwitch": "Verbose" },
    "MinimumLevel": {
      "Default": "Debug",
      "Override": {
        "Microsoft": "Warning"
      }
    },
    "WriteTo": [
      {
        "Name": "Debug"
      },
      {
        "Name": "MySQL",
        "Args": {
          "connectionString": "Serilog",
          "tableName": "serilog",
          "storeTimestampInUtc": "false"
        }
      }
    ],
    "Enrich": [ "FromLogContext" ]
  },
  "ConnectionStrings": {
    "Serilog": "Server=<my server>;Database=<my db>;Uid=<my user>;Pwd=<mypassword>;"
  }
}

If I specify the connection string manually by adding the following line to the code documented in the link above, everything works normally:

.UseSerilog((hostingContext, loggerConfiguration) => loggerConfiguration
  .ReadFrom.Configuration(hostingContext.Configuration)
  .WriteTo.MySQL(hostingContext.Configuration.GetConnectionString("Serilog")))

Do I have the configuration incorrect in the settings file?

@skoruba
Copy link

skoruba commented Dec 2, 2019

Does work for you?
Thanks

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