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

Console Logger Filtering via IConfiguration - Issues #526

Closed
@MichaCo

Description

@MichaCo

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions