serilog / serilog-aspnetcore

Serilog integration for ASP.NET Core
Apache License 2.0
1.29k stars 203 forks source link

UseSerilog() does not initialise logging when using IHostBuilder #366

Closed OwenPattison closed 2 weeks ago

OwenPattison commented 4 months ago

The Serilog maintainers want you to have a great experience using Serilog, and will happily track down and resolve bugs. We all have limited time, though, so please think through all of the factors that might be involved and include as much useful information as possible 😊.

ℹ If the problem is caused by a sink or other related package, please try to track down the correct repository for that package and create the report there: this tracker is for the Serilog.AspNetCore package only.

Description UseSerilog() does not initialise

Reproduction Please provide code samples showing how you're configuring and calling Serilog to produce the behavior. We have recently switched from IWebHostBuilder to IHostBuilder to resolve warnings and the obsolete method, however in doing so and using the UseSerilog() method on IHostBuilder we no longer have any logs, the fallback I've had to use: UseSerilog() within .ConfigureWebHostDefaults() which is obsolete.

      return Host
            .CreateDefaultBuilder(args)
            .UseSerilog((hostingContext, config) =>
                    {
                        config.ReadFrom.Configuration(hostingContext.Configuration);
                        config.Enrich.FromLogContext();
                    })
      ...

While debugging I can see the method UseSerilog() being called but if I break inside - it never resolves.

Expected behavior Logger to be created and sinks setup.

Relevant package, tooling and runtime versions .net core 6

Package="Serilog.AspNetCore" Version="6.1.0"

Package="Serilog.Settings.Configuration" Version="7.0.1" Package="Serilog.Sinks.ApplicationInsights" Version="3.1.0" Package="Serilog.Sinks.Console" Version="4.1.0" Package="Serilog.Sinks.RollingFileAlternate" Version="2.0.9" Package="Serilog.Sinks.Seq" Version="5.2.2" Package="Serilog.Sinks.Trace" Version="3.0.0" Package="SerilogTimings" Version="3.0.1"

Additional context No changes to how we setup serilog only the builder. I also believe this relates to: https://github.com/serilog/serilog-aspnetcore/issues/254 this issue

bartelink commented 4 months ago

You're way better off posting this sort of thing on stack overflow - anyone that's going to be watching this repo also has a subscription to the serilog tag over there, so you'll get way more eyes on it there.

After doing triage and/or analysis over there, it may well turn out that an issue (with a failing test or a clear objective in terms of how the API should be revised etc) might be the answer.

Right now, all we have is 39 watchers (not all of whom use/have used/have troubleshooted the package), who scan these issues but are likely in the middle of their working day so are not likely to jump in and Just Answer (also many will be turned off even trying to figure it out by the failure to format the message properly and/or remove boilerplate that's obviously supposed to eb removed to yield a legible answer)

nblumhardt commented 2 weeks ago

Can't spot anything obvious in this one, but also not a lot of info to go on. As Reuben suggests, posting to SO with a full code sample would be a better bet (please feel free to update here with a link to that post if needed).