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

Console Logger Filtering via IConfiguration - Issues #526

Closed
MichaCo opened this issue Nov 30, 2016 · 4 comments
Closed

Console Logger Filtering via IConfiguration - Issues #526

MichaCo opened this issue Nov 30, 2016 · 4 comments
Assignees

Comments

@MichaCo
Copy link

MichaCo commented Nov 30, 2016

There are two catches which might be intended or not

First, the values in the configuration are parsed case sensitive. If you put "error" in lower case, you'll get an exception.

This could easily be changed by calling Enum.Parse(, true, ...) instead of

else if (Enum.TryParse<LogLevel>(value, out level))
{
    return true;
}

in ConfigurationConsoleLoggerSettings line 65

The second issue is a few lines later, it actually throws an exception whenever it cannot parse the enum.

            else if (Enum.TryParse<LogLevel>(value, out level))
            {
                return true;
            }
            else
            {
                var message = $"Configuration value '{value}' for category '{name}' is not supported.";
                throw new InvalidOperationException(message);
            }

I think that's bad.
For the initial application startup, this might be fine, but if you work with reload tokens, the whole logic blows up if you make one mistake one time:
If the configuration has been updated with a wrong configuration value, the token triggers but the code above throws an exception. The exception doesn't get logged or shown anywhere because it's an async "somewhere" task doing the checks...
Because of the exception, no new token and handler get created afterwards, and I have to restart the application to have it read the updated configuration again...

@MichaCo
Copy link
Author

MichaCo commented Jan 17, 2017

@muratg @glennc Hey guys, any comment on this
Thanks, M

@glennc
Copy link
Member

glennc commented Jan 19, 2017

We need to add a finally or something to the logger providers that handle change tokens (like Console). They appear to already have the logic to reset the token, it just gets skipped on an exception.

I think the ideal experience here would be that if any errors occur during reloading of configuration we leave everything as it was before the config was changed, so none of your changes apply until you fix whatever is breaking and then all of them take affect. The reason I think that is because we should also log the fact that an error happened and it seems most likely to be log successfully if we ignore all the changes that caused an exception.

@BrennanConroy
Copy link
Member

Fixed via 6525bff

@MichaCo
Copy link
Author

MichaCo commented Feb 22, 2017

@BrennanConroy Great 👍

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

4 participants