tmds / Tmds.Systemd

.NET Core library for interacting with systemd
Other
128 stars 17 forks source link

Add ProviderAlias to JournalLoggerProvider #33

Closed ATLSAPI closed 5 years ago

ATLSAPI commented 5 years ago

Hi @tmds, first I want to say this library has been great for us. Now to the issue.

JournalLoggerProvider is missing the [ProviderAlias] attribute (introduced in NET Core 2.0), and therefore uses the default logging configuration unless we use the fully qualified name Tmds.Systemd.Logging.JournalLoggerProvider.

The goal is to reuse the provider targeted logging configuration section of appsettings.json.

Currently, to achieve that we need to specify the full namespace of JournalLoggerProvider as follows:

"Logging": {
    "IncludeScopes": false,
    "LogLevel": {
        "Default": "Debug",
        "System": "Information",
        "Microsoft": "Information"
    },
    "Tmds.Systemd.Logging.JournalLoggerProvider": {
        "IncludeScopes": false,
        "LogLevel": {
            "Default": "Warning",
            "System": "Warning",
            "Microsoft": "Warning",
            "Microsoft.AspNetCore.Hosting.Internal.WebHost": "Information"
        }
    }
}

By adding [ProviderAlias("Journal")] for example, we can simplify above config to below

"Logging": {
    "IncludeScopes": false,
    "LogLevel": {
        "Default": "Debug",
        "System": "Information",
        "Microsoft": "Information"
    },
    "Journal": {
        "IncludeScopes": false,
        "LogLevel": {
            "Default": "Warning",
            "System": "Warning",
            "Microsoft": "Warning",
            "Microsoft.AspNetCore.Hosting.Internal.WebHost": "Information"
        }
    }
}

I'm happy to create a pull request if that helps?

tmds commented 5 years ago

Hi @tmds, first I want to say this library has been great for us.

Thanks!

By adding [ProviderAlias("Journal")] for example, we can simplify above config to below

Yes, that's nicer.

I'm happy to create a pull request if that helps?

Please do.

ATLSAPI commented 5 years ago

Please do.

I'll do that. With regards to versioning do I need to increment (0.5.1 as its a patch) or shall I leave it you/some automated build process you may have in place?

tmds commented 5 years ago

Yes, please update the build number in:

https://github.com/tmds/Tmds.Systemd/blob/6b3fe56180455e5d38e1ce6efc16ded17baf7f73/Directory.Build.props#L3

You can set it to 0.6.0.

ATLSAPI commented 5 years ago

Cool. I've updated #34 now

tmds commented 5 years ago

Fixed in https://github.com/tmds/Tmds.Systemd/pull/34. Available in 0.6.0.