我使用以下代码创建了一个托管服务:
class Program
{
static async Task Main(string[] args)
{
await new HostBuilder()
.ConfigureAppConfiguration((hostContext, configApp) =>
{
configApp.AddEnvironmentVariables(prefix: "SAMPLEHOST_");
configApp.AddCommandLine(args);
})
.ConfigureServices((hostContext, services) =>
{
services.AddHostedService<SampleHostedService>();
services.AddHostedService<AnotherHostedService>();
})
.ConfigureLogging((hostingContext, logging) =>
{
logging.AddConsole();
})
.RunConsoleAsync();
}
}
...具有以下launchsettings.json
.
{
"profiles": {
"SampleHost.Cli": {
"environmentVariables": {
"LOGGING__LOGLEVEL__DEFAULT": "Debug",
}
}
}
}
我似乎无法让它出现在我的控制台中。:(
Logger.LogDebug("Hello debug");
我想修改和调整LogLevel
纯粹的环境变量。我错过了什么吗?