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.

Request: pass less data into ReadFrom.Configuration

See original GitHub issue

This is the typical setup:

var configuration = getConfiguration();
var logger = new LoggerConfiguration()
  .ReadFrom.Configuration(configuration);
  .CreateLogger();

However that passes the entire appsettings.json into ReadFrom.Configuration(). Which is not a good idea - Serilog should get only that config data it needs, no more.

It would be more robust to OPTIONALLY replace this:

.ReadFrom.Configuration(configuration);

with this:

.ReadFrom.Configuration(configuration.GetSection("Serilog"));

Both forms would be allowed to ensure backwards compatibility. Serilog would then need to decide whether the json tree it gets has “Serilog” as the root node, or not, and proceed accordingly.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
tsimbalarcommented, Jul 6, 2018

Hi and thank you for opening an issue.

I believe both overloads already exist :

public static LoggerConfiguration Configuration(
    this LoggerSettingsConfiguration settingConfiguration,
    IConfiguration configuration,
    DependencyContext dependencyContext = null)
    {}

public static LoggerConfiguration ConfigurationSection(
    this LoggerSettingsConfiguration settingConfiguration,
    IConfigurationSection configSection,
    DependencyContext dependencyContext = null)
    {}

Doesn’t that cover your remarks ?

Thanks

0reactions
lonix1commented, Jul 6, 2018

Also true. And in that case there would be duplication of such connection strings which is a recipe for trouble.

I’m glad the overload exists because it’s good enough for my use case.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Serilog cannot find the appsettings file using readfrom
I am trying to configure a serilog logger using the appsettings.json file which is located in my.net core bin base directory.
Read more >
A Serilog configuration provider that reads from Microsoft. ...
By default, configuration is read from the Serilog section. After installing this package, use ReadFrom. Configuration() and pass an IConfiguration object. ...
Read more >
[Fix]-Serilog ReadFrom Configuration - appsloveworld.com
Here is how I did it to read from logging.json: var builder = new ConfigurationBuilder() .AddJsonFile(path: "logging.json", optional: false, ...
Read more >
How to log to Console with .NET Core and Serilog
In this article, we will see how to add Serilog, a popular logger library, to our .NET projects: we will learn how to...
Read more >
What every ASP.NET Core Web API project needs - Part 1
In a series of articles, I'm going to show the implementation of an architecture that is suitable for a thin Web API project...
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