.NET Core 2.2, WebJobs SDK 3.0
I have a webjob that I configure like this :
var environmentName = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Development";
HostBuilder builder = new HostBuilder();
builder.ConfigureAppConfiguration((context, configApp) => {
configApp.AddEnvironmentVariables();
configApp.AddJsonFile("appsettings.json", optional: true);
configApp.AddJsonFile($"appsettings.{environmentName}.json",optional: false);
});
builder.ConfigureHostConfiguration((configApp) => {
configApp.AddEnvironmentVariables();
configApp.AddJsonFile("appsettings.json", optional: true);
configApp.AddJsonFile($"appsettings.{environmentName}.json", optional: false);
});
I have a appsettings.test.json
file deployed to my environment and when I check my environment variable, I have indeed test
as the environment.
I can see that the file gets loaded because optional is false and I don't have any exception.
However, when my webjob starts, it doesn't use the storage connection string I have in my appsettings.test.json, it uses the one in appsettings.json
My AppInsights connection doesn't work either and I initializes it like this :
builder.ConfigureLogging((context, b) => {
b.AddConfiguration(context.Configuration.GetSection("Logging"));
Console.WriteLine($"App Insight key is {context.Configuration["ApplicationInsights:InstrumentationKey"]}");
b.AddApplicationInsightsWebJobs(o => o.InstrumentationKey = context.Configuration["ApplicationInsights:InstrumentationKey"]);
});
When the code runs, the Console shows the App Insights Key that is in the appsettings.json and not the appsettings.test.json
What can I do to force the host to use my appsettings.test.json?