Skip to content
This repository has been archived by the owner on Mar 1, 2022. It is now read-only.

Configuration from appsettings.json #30

Closed
ddshpak opened this issue Dec 8, 2017 · 7 comments
Closed

Configuration from appsettings.json #30

ddshpak opened this issue Dec 8, 2017 · 7 comments

Comments

@ddshpak
Copy link
Contributor

ddshpak commented Dec 8, 2017

I haven't been able to find a good way to do configuration-driven setup of the Loggly sink in a .NET Core app. It doesn't look like I can specify anything like

{
  "Serilog": {
    "WriteTo": [
      {
        "Name": "Loggly",
        "Args": {
          "logglyConfig": {
            "CustomerToken": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
            "ApplicationName": "SerilogTest"
          }
        }
      }
    ]
  }
}

because that fails with System.InvalidOperationException: Argument value should be of type Action<>.. And in a .NET Core app, I don't have an app.config file, so I can't use loggly-csharp-configuration's XML-based configuration (as far as I know).

Am I missing something? Or is the current state of affairs such that I need to do programmatic configuration of Loggly in a .NET Core application?

@MiguelAlho
Copy link
Contributor

Hi and sorry for the very delayed response. Yes, at the moment, the LogglyConfiguration object should be built/composed to pass that info in.

I saw that you have created a PR (#31) and will look into it.

@MiguelAlho
Copy link
Contributor

Is https://github.com/serilog/serilog-settings-configuration a viable solution for this (instead of changing the public interface of the extension method)?

@MiguelAlho
Copy link
Contributor

I've seen from serilog/serilog-settings-configuration#58 that it's not yet possible to configure complex objects as args, so the list of args would need to be flattened.

@ddshpak
Copy link
Contributor Author

ddshpak commented Jan 16, 2018

Hi @MiguelAlho,

My understanding of https://github.com/serilog/serilog-settings-configuration is that it will take any settings it finds in the supplied JSON, and inject them as constructor parameters...but, as you point out, it doesn't support complex objects as arguments.

I didn't want to flatten the entire LogglyConfiguration object into simple-valued constructor arguments, so I took the approach of just adding the three that seemed the most important: the customer token (absolutely required), the tags (very valuable), and the endpoint (probably not needed, to be honest).

With these new arguments in place, https://github.com/serilog/serilog-settings-configuration does the rest of the work of actually parsing the JSON and passing in the correct arguments. The change to the public interface is backwards-compatible (the new arguments have default values).

I'm quite new to Serilog, so I might be missing something that should be obvious. If there's a better way to leverage the existing configuration code, I'd be happy to try to implement it; I might just need to be pointed in the right direction.

Thanks!

@MiguelAlho
Copy link
Contributor

I tried building a sample using serilog-settings-configuration, but it unfortunately does not support complex objects. If it did, the sample you provided above would have been enough. It may be better to include support for the params, as you have in your PR.

@skomis-mm
Copy link

Hi, @dshpak-iq , @MiguelAlho. This should work with 3.0+ of the Serilog.Settings.Configuration package.

@MiguelAlho
Copy link
Contributor

I've added a sample project in the features/jsonConfig branch that can be used to test things like this out. At the moment, Using the sample, I can send messages to loggly using just the appsettings.json file to configure the logger, though I'm not testing the durable logger just yet.

PR: #53 to put this in the dev branch

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

No branches or pull requests

3 participants