Giter Site home page Giter Site logo

Comments (10)

davidfowl avatar davidfowl commented on May 12, 2024 1

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.

from todoapi.

davidfowl avatar davidfowl commented on May 12, 2024

I don't see how you can add new sinks at runtime without also adding a nuget package for that sink (maybe you meant, configure existing sinks?). As for changing log levels at runtime, that's important.

from todoapi.

PureKrome avatar PureKrome commented on May 12, 2024

I don't think it's runtime? The app will need to be restarted manually or via (I think) an OptionsSnapshot or IOptionsMonitor ? (reloadable configuration?)

from todoapi.

davidfowl avatar davidfowl commented on May 12, 2024

Adding/Changing sinks dynamically I wouldn't want to be in this application. Configuring existing sinks via config is good.

from todoapi.

PureKrome avatar PureKrome commented on May 12, 2024

kewl! that would be fine via the official Serilog Configuration nuget.

So you're happy for a PR to come, enabling this option? (no I haven't done anything yet -> just touching base first, etc).

from todoapi.

davidfowl avatar davidfowl commented on May 12, 2024

Just so I understand, isn't this what's happening here?

from todoapi.

PureKrome avatar PureKrome commented on May 12, 2024

Ah yes! that's correct actually. That's what I was going to do.

<Reads the code .... >

but wait .. i feel like the current setup is incomplete.

see this code here:

image

this looks like it's a poor persons way of using configuration but then having to still hardcode the code based on some config values.

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).

Here's some code to explain:

  • remove this
if (serilogOptions.UseConsole)
{
    // https://github.com/serilog/serilog-sinks-async
    loggerConfiguration.WriteTo.Async(writeTo =>
    writeTo.Console(outputTemplate: serilogOptions.LogTemplate));
}

then add this to appsettings.json :

image

  1. This is any "not-default" sinks that you want to use. It's basically the namespace of the nuget package that isn't in the default Serilog nuget. This is where you would add DataDog, Splunk, etc.. if that's where u want to send data to.
  2. This is a customizable way to determine what to "enrich" each log, with. It's identical to:

image

.. except, this way, you can change the enrichment if your want .. versus .. having it hardcoded for every log. Sure, you might say "I want the log-context" value in each log message. But I personally really like picking one (hardcoding) or the other (configuration source) as the one place to define all of this. I just feel like, having this defined in a configuration source gives you more options later on. Say, test environment is playing up ... you can play with the enrichment values here to get more data, if needed.

  1. Just another key/value that is added with each log message. Or should I say, each log message is "enriched" with this key/value. You have this hardcoded.
  2. Console sink: pretty simple. No customization required. Just -> log to the console, please.
  3. Seq sink: this is a bit more complicated but it's where the seq settings will go. Usually it's a form of the sink's "constructor". Can also support arrays in here. Nick Blum has done a great job here, IMO.

and of course, you can keep adding more sinks in here - as required. And different environments (dev/test/prod) could of course have different sinks and/or different log levels, etc.

I hope this makes any sense, at all 😊

from todoapi.

PureKrome avatar PureKrome commented on May 12, 2024

Added draft PR #62 . Not sure if you get notifications for draft PR's.

from todoapi.

davidfowl avatar davidfowl commented on May 12, 2024

I've decided to swap out serilog in favor of the otel logging pipeline.

from todoapi.

PureKrome avatar PureKrome commented on May 12, 2024

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

from todoapi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.