serilog / serilog-extensions-hosting

Serilog logging for Microsoft.Extensions.Hosting
Apache License 2.0
141 stars 34 forks source link

Add IServiceCollection extension methods to enable serilog #66

Closed eerhardt closed 1 year ago

eerhardt commented 2 years ago

With https://github.com/dotnet/runtime/issues/61634#issuecomment-1033038101 and https://github.com/dotnet/runtime/pull/65109, Microsoft.Extensions.Hosting added a new way of creating a hosted app that doesn't use IHostBuilder.

We should add overloads to SerilogHostBuilderExtensions that accept an IServiceCollection instead of an IHostBuilder. This will allow consumers using the new HostApplicationBuilder to use Serilog easily.

Since the methods will extend IServiceCollection, the methods should probably be named AddSerilog instead of UseSerilog. This follows the naming patterns used elsewhere.

See also https://github.com/dotnet/runtime/pull/68580 and https://github.com/dotnet/aspnetcore/pull/43056

cc @davidfowl

nblumhardt commented 2 years ago

Thanks for the heads-up @eerhardt :+1:

mburumaxwell commented 1 year ago

@nblumhardt Is this anywhere in the new future or are you accepting contributions for it?

From the look of things in https://github.com/serilog/serilog-extensions-hosting/blob/dev/src/Serilog.Extensions.Hosting/SerilogHostBuilderExtensions.cs, the is nothing closely tying the logic to IHostBuilder or HostBuilderContet except for the callbacks. I made the changes locally to create new extensions on IServiceCollection that are then used by the existing extensions on IHostBuilder and all seems fine. I could submit a PR for the this.

nblumhardt commented 1 year ago

A PR for this would be very welcome, thanks @mburumaxwell 👍

mburumaxwell commented 1 year ago

Done. You can review it when you get a chance.