I initially configured my Console application using .NET generic host as follows:
var builder = new HostBuilder() .ConfigureServices((hostContext, services) => { services.AddLogging(); }) .ConfigureLogging((hostContext, configLogging) => { configLogging.AddConsole(); }) .UseConsoleLifetime() .Build(); await builder.RunAsync(); Then I realized I also needed appsettings.json and appsettings.{Environment}.json, which led me to the decision to use Host.CreateDefaultBuilder, as it includes the default logging, appsettings, and some other defaults:
var host = Host.CreateDefaultBuilder(args) .ConfigureServices(services => { }) .UseConsoleLifetime() // Is this line necessary? .Build(); Now I wonder if UseConsoleLifetime is actually included in the default builder. I wasn't able to find it by decompiling several source code files, but just to be sure, I decided to ask this question.
Here is the Microsoft docs:
- https://learn.microsoft.com/en-us/dotne ... ostbuilder
- https://learn.microsoft.com/en-us/dotne ... t-shutdown
Источник: https://stackoverflow.com/questions/780 ... reatedefau
Мобильная версия