I am trying to add appsettings.json
file for different environments. How do I get environment name in program.cs
in .NET 8 that looks like this:
var options = new ConfigurationBuilder()
.SetBasePath(AppContext.BaseDirectory)
#if DEBUG
.AddJsonFile("local.settings.json")
#else
.AddJsonFile("appsettings(pass the env name).json")
#endif
.Build();
var host = new HostBuilder()
.ConfigureFunctionsWorkerDefaults()
.ConfigureServices(services =>
{
services.AddApplicationInsightsTelemetryWorkerService();
services.ConfigureFunctionsApplicationInsights();
})
.Build();
host.Run();
There are several posts here, but none of those are recognized in .NET 8, most are for .NET 6.
Build();
var host = new HostBuilder() .ConfigureFunctionsWorkerDefaults() .ConfigureServices(services => { services.AddApplicationInsightsTelemetryWorkerService(); services.ConfigureFunctionsApplicationInsights(); }) .Build(); host.Run();
host.Run();
tesfaye girma is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.