Skip to content
This repository has been archived by the owner on Dec 13, 2018. It is now read-only.

Configuring logging from appSettings.json #437

Closed
RehanSaeed opened this issue May 24, 2016 · 13 comments
Closed

Configuring logging from appSettings.json #437

RehanSaeed opened this issue May 24, 2016 · 13 comments

Comments

@RehanSaeed
Copy link

The Console logger has the following method which allows you to configure it from the appSettings.json file:

loggerFactory.AddConsole(configuration.GetSection("Logging"));
"Logging": {
  "IncludeScopes": true,
  "LogLevel": {
    "Default": "Debug",
    "System": "Information",
    "Microsoft": "Information"
  }
}

Why do the Debug, EventLog and other loggers not have similar overloads? What was the intention behind that decision. In my case, I would like a configuration section in the JSON for each log provider so that they could be configured independently. What would be the best way to achieve this?

@muratg
Copy link

muratg commented May 26, 2016

Thanks @RehanSaeed. Looks like an additive chance, so putting into 1.0.1 milestone for further discussion post RTM.

@cwe1ss
Copy link
Contributor

cwe1ss commented Jul 12, 2016

This example shows well that the existing providers are really fragmented in terms of filtering and configuration. Providers should not be responsible for implementing this on their own. this makes creating new providers way too complicated.

If you want to improve this library, you should make file-based configuration and filtering a single, centralized responsibility (e.g. remove the provider-specific filters in favor of the new filter-package or create some other integrated solution)

However, I'm in favor of not improving the providers and instead focusing on making the integration with 3rd party loggers better. :)

@galmok
Copy link

galmok commented Sep 27, 2016

I would like to see a way to configure log levels from appsettings.json using WithFilter (FilterLoggerSettings) as I currently have to hardcode the loglevels. I am using SeriLog and as such have no use for the AddConsole output feature. But I do need the filtering.

@muratg
Copy link

muratg commented Sep 27, 2016

cc @davidfowl

@muratg muratg modified the milestones: Backlog, 1.1.0-preview1 Oct 5, 2016
@ToddThomson
Copy link

Having a LoggingFilter app settings configuration with overrides for specific providers would be nice.

@jorgeyanesdiez
Copy link

jorgeyanesdiez commented Nov 17, 2016

Looking at the current docs I'm confused. Is there a way to do something like this?

var settings = configuration.GetSection("Logging");
or even
var settings = configuration.GetValue<FilterLoggerSettings>("Logging");

which can then be used like:
var loggerFactory = new LoggerFactory().WithFilter(settings);

given that my appsettings.json contains the standard block in the first message in this thread?

That'd be pretty handy instead of having to read the json myself and then creating the IFilterLoggerSettings instance, i.e: NOT having to do this.

var loggerSettings = new FilterLoggerSettings();
var logLevels = configuration.GetSection("Logging:LogLevel").GetChildren();
foreach(var logLevel in logLevels)
{
    var logLevelValue = default(LogLevel);
    Enum.TryParse(logLevel.Value, ignoreCase: true, result: out logLevelValue);
    loggerSettings.Add(logLevel.Key, logLevelValue);
}

var loggerFactory = new LoggerFactory()
    .WithFilter(loggerSettings);

@MichaCo
Copy link

MichaCo commented Nov 29, 2016

@joelmartinez totally agree, you should probably add a feature request for that. Shouldn't be too hard to do as it is already done for console logging

@davidfowl
Copy link
Member

@muratg @Eilon @DamianEdwards Lets add this to the 2.0.0 milestone.

@Eilon Eilon removed this from the Backlog milestone Feb 19, 2017
@Eilon
Copy link
Member

Eilon commented Feb 19, 2017

Yeah this is a reasonable feature request. Will have to look at what else we have for 2.0.0, but this one seems fairly bite-sized.

@DamianEdwards
Copy link
Member

👍

@glennc glennc added this to the 2.0.0 milestone Mar 1, 2017
@muratg muratg modified the milestones: 2.0.0-preview1, 2.0.0-preview2 Apr 21, 2017
@muratg muratg removed this from the 2.0.0-preview2 milestone May 25, 2017
@muratg
Copy link

muratg commented May 25, 2017

@pakrym is this bug still necessary with the changes you're working on?

@pakrym
Copy link
Contributor

pakrym commented May 25, 2017

Yes, there would be global filter configuration.

@muratg muratg added this to the 2.0.0-preview3 milestone May 26, 2017
@pakrym
Copy link
Contributor

pakrym commented Jun 22, 2017

Fixed by #626
Filter configuration is global now and can be applied to any provider.

@pakrym pakrym closed this as completed Jun 22, 2017
@pakrym pakrym added 3 - Done and removed 1 - Ready labels Jun 22, 2017
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