Open komayama opened 3 years ago
I was able to reproduce this bug on two separate Function apps running host version 3.0.15185.0 in Azure (Central US.) See below screenshot. Repro code was modified slightly for clarity.
Interestingly, I was not able to reproduce the bug locally; supplying different AZURE_FUNCTIONS_ENVIRONMENT values on my local machine resulted in expected behavior. Possibly a platform caching issue?
Results by setting value Between each change, the host restarted with a new PID.
Direct setting read vs IHostingEnvironment.IsDevelopment() return value
Repro Code
using System;
using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
namespace _6978repro
{
public class Function1
{
private readonly IHostEnvironment _hostEnvironment;
private readonly IConfiguration _configuration;
public Function1(IHostEnvironment hostEnvironment, IConfiguration configuration)
{
_hostEnvironment = hostEnvironment ?? throw new ArgumentNullException(nameof(hostEnvironment));
_configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));
}
[FunctionName("Function1")]
public void Run([TimerTrigger("0 */1 * * * *")] TimerInfo myTimer, ILogger log)
{
log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");
log.LogInformation($"_hostEnvironment.IsDevelopment(): {_hostEnvironment.IsDevelopment()}");
log.LogInformation($"_hostEnvironment.IsProduction(): {_hostEnvironment.IsProduction()}");
log.LogInformation($"AZURE_FUNCTIONS_ENVIRONMENT: {Environment.GetEnvironmentVariable("AZURE_FUNCTIONS_ENVIRONMENT")}");
}
}
}
AZURE_FUNCTIONS_ENVIRONMENT value not reflect in Windows Plan
I create code that call IHostEnvironment interface IsDevelopment method for switching Development and Production environment when use the following the Environment as a application setting in Azure Functions on Windows consumption, AppService, Premium Plan.