Closed lonix1 closed 6 years ago
Likely duplicate of https://github.com/aspnet/Hosting/issues/1430
Rather than duplicating your config builder in ConfigureAppConfiguration, you could chain in the config you've already built with config.UseConfiguration(configuration). That should honor reload better than WebHostBuilder.UseConfiguration.
@Tratcher That did it! Like mentioned in the issue you linked, some of the docs are confusing, but I'm glad you mentioned this will be reworked in 3.x.
For anyone who needs this, the exact solution is:
.ConfigureAppConfiguration((context, config) => {
config.AddConfiguration(configuration);
})
I want to start logging before webhost, so startup errors are logged. So I followed Serilog's recommended init order: 1) configuration, 2) logging, 3) webhost. I'm not using
CreateDefaultBuilder()
.So my
Program.cs
has:This works, but changes in
appsettings.json
are not detected even though I specifiedreloadOnChange:true
.However when I use
ConfigureAppConfiguration()
then changes are detected:But that means duplication and possibly unforseen problems.
There are various issues around this, but without being an expert in the underlying framework, they don't address my problem. Can this be solved, is it a bug, by design, or am I doing it wrong?
EDIT The docs change often so I didn't see this which implies that I should use
ConfigureAppConfiguration()
. However the problem remains - how do I do this neatly without duplicating code?