Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update README.md example to show builder.Services.AddSerilog() in a minimal API project #368

Closed
nblumhardt opened this issue Mar 28, 2024 · 4 comments · Fixed by #370
Closed

Comments

@nblumhardt
Copy link
Member

See serilog/serilog#1855 (comment)

@crozone
Copy link

crozone commented Apr 4, 2024

Should this be builder.Services.AddSerilog() or builder.Logging.Services.AddSerilog()?

@nblumhardt
Copy link
Member Author

Digging into this some more, I think it should actually be:

builder.Host.UseSerilog()

The reason being, currently, that the callback accepted by this version exposes the appsettings.json IConfiguration, while builder.Services.AddSerilog() doesn't.

I think builder.Services and builder.Logging.Services will end up equivalent, but let me know if it turns out that I'm mistaken :-)

@nblumhardt
Copy link
Member Author

Just noting that the minimal API template uses WebApplication.CreateBuilder(), which is different from the IHostApplicationBuilder being discussed in serilog/serilog-extensions-hosting#76

@nblumhardt
Copy link
Member Author

Seems like we should encourage builder.Services.AddSerilog(lc => ..) everywhere, since it works with both host styles, and handles configuration a bit more elegantly with AddSerilog(lc => lc.ReadFrom.Configuration(builder.Configuration)) instead of needing the second callback arg.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants