datalust / seq-forwarder

Local collection and reliable forwarding of log data to Seq
Apache License 2.0
57 stars 15 forks source link

Optionally use Environment Variables for Config #57

Closed stevekirks closed 3 years ago

stevekirks commented 3 years ago

Hi Nick

I've had a go at implementing Environment Variables for the config. Hopefully it's what you had in mind but you may have a better strategy. Here's some explanations for the pull request;

Example Environment Variable names: FORWARDER_OUTPUT_RAWPAYLOADLIMITBYTES FORWARDER_DIAGNOSTICS_INTERNALLOGGINGLEVEL

Its using the Microsoft.Extensions.Configuration.ConfigurationBuilder to load the Environment Variables and the GetValue() method to get each variable the right type.

Its renamed property EncodedApiKey to ApiKey so that the environment variable FORWARDER_OUTPUT_APIKEY would match. (Also updated the check that excludes it in ConfigCommand).

With these changes, the Config command lists the config file with environment variables overwritten, and writes update the config file with any changes as well as any overwritten environment variables. Not sure if that is the expectation.

If you have ideas for improvement I'm all ears. If you think a different way would be better that's ok too.

Addresses #55

nblumhardt commented 3 years ago

That's great - thanks Steve! Will check this out ASAP 👍

stevekirks commented 3 years ago

For the Config command, I've changed it so it only reads from the config file (env vars aren't loaded). More what the user expects? (https://github.com/datalust/seq-forwarder/pull/57/commits/6744940073e539f447dada64911befefe4702caf)

nblumhardt commented 3 years ago

Looks great, thanks Steve 👍