I am troubleshooting an Azure WebJob's custom configuration and trying to work out what the expected behaviour should be. I understand that for AppSettings, a webjob will read those from the AppService web.config. But for a custom configuration section, I am not getting that configuration in the web job.
If I add the custom configuration to the webjob app.config, the webjob will read that configuration correctly.
What is the expected behaviour between the webjob app.config and the appservice web.config?
What is the expected behaviour between the webjob app.config and the appservice web.config?
The expected behavior is that the WebJob will read the AppSettings from the AppService web.config, but for a custom configuration section, it will not read that configuration in the WebJob. If you want to read a custom configuration section in your WebJob, you will need to add it to the WebJob's app.config file.
I have created a console application in visual studio and then deployed in azure webjobs.
Iam able get the hello world output in webjob logs.
Then, I tried to add the custom configuration to the webjob app.config
as check below.
<configuration>
<appSettings>
<add key="MySetting" value="MyValue" />
</appSettings>
</configuration>
Added the below code in program.cs
and install Microsoft.Extensions.Configuration in your NuGet packages installer.
var configuration = new ConfigurationBuilder()
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.Build();
var setting1 = configuration["Setting1"];
var setting2 = configuration["Setting2"];
Console.WriteLine($"Setting1 value: 123 {setting1}");
Console.WriteLine($"Setting2 value: 432 {setting2}");
Iam able run the app successfully in my local.
Then I re-deployed to the webjob and as expected am able run successfully.
Here are the logs.