0

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?

Jay Cummins
  • 1,039
  • 2
  • 14
  • 31
  • Hi @Jay Cummins, can you please elaborate your requirement for better understanding whether the differences or expected behavior on custom configuration. – Suresh Chikkam Apr 13 '23 at 12:23

1 Answers1

2

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.

enter image description here

Iam able get the hello world output in webjob logs.

enter image description here

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.

enter image description here

Then I re-deployed to the webjob and as expected am able run successfully.

enter image description here

Here are the logs.

enter image description here

Suresh Chikkam
  • 623
  • 2
  • 2
  • 6