question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Serilog is better when the settings are via config sources

See original GitHub issue

👋🏻 G’day @davidfowl

So now that Serilog has been merged (ref: #49) I was hoping you might consider another Serilog PR which now removes any hardcoding of serilog settings and instead replacing them with the settings being defined via configuration sources.

Serilog has it’s own special Serilog Configuration nuget which it then knows how to define some serilog settings via .NET configuration (file/env vars/etc):

image

The obvious example here is via the appsettings.json, given a specific “section”. This extends to env vars so it works really nicely with Azure App Services or Docker Containers.

Can even use “Secrets” if you really need to -> think, API/License keys fr for the logging sink which is in the cloud.

Why do this?

This means anyone can easily change/setup their “sinks” and/or their logging “levels” at any time, without requiring any new build/deploys. For example, something weird is going on, you could just edit the azure app settings “env vars”/configuration settings and mod the logging level for a specific class or just in general (i.e. all logging is now Debug, not Info) … etc.

Would you be interested in this?

Issue Analytics

  • State:closed
  • Created 9 months ago
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
davidfowlcommented, Dec 27, 2022

What happens if I want to send the logs to DataDog or any of the other provided sinks? If I wish to now send the data to DDog or Splunk or whatever, I need to hardcode. With the config file method, I can set everything up via the configuration source. The biggest “catch” is that the relevant nuget file needs to be in the bin. (I’ve never tried manually putting a nuget to a bin, post deployment).

That seems logical to me. Add the nuget package, choose to configure it in code or via config. Adding sinks dynamically isn’t something that makes sense IMO.

I think it makes sense to move some things to config but not all of them. For example, I need to be able to detect when a URL is configured so that I can dynamically enable one of those sinks (elastic search for e.g.). Does the configuration model support branches (if statements etc)?

Today I can pass in the application name from the hosting environment but when using config, I need to duplicate that name. There are tradeoffs. Also, I can set breakpoints in code 😄.

That said, send me a PR and we can go back and forth until we meet somewhere in the middle.

0reactions
PureKromecommented, May 5, 2023

okay - i have more to learn, it seems! looking forward to seeing what/why/etc 😃 kewl!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Configuration Basics · serilog/serilog Wiki
Serilog uses a simple C# API to configure logging. When external configuration is desirable it can be mixed in (sparingly) using the Serilog ......
Read more >
Serilog Best Practices - Ben Foster
Serilog can be configured using either a Fluent API or via the Microsoft Configuration system. We recommend using the configuration system since ...
Read more >
Filter Serilog logs to different sinks depending on context ...
Using a logger as a sink, as described at the bottom of https://github.com/serilog/serilog/wiki/Configuration-Basics did the trick.
Read more >
Serilog Tutorial for .NET Logging: 16 Best Practices and Tips
Logging frameworks make it easy to send your logs to different places via simple configurations. Serilog uses what are called sinks to send ......
Read more >
Serilog — simple .NET logging with fully-structured events
NET, Serilog provides diagnostic logging to files, the console, and elsewhere. It is easy to set up, has a clean API, and is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found