Reputation: 8009
I need to check what environment, local or Azure, Azure Functions is running on.
Below is the code based on this and this
var isLocal = string.IsNullOrEmpty(GetEnvironmentVariable("WEBSITE_INSTANCE_ID")
Is this a documented feature, or stable feature?
If not, is there an alternative?
Azure function 2.x
VS 2017
Upvotes: 2
Views: 3104
Reputation: 1550
Azure App Service sets some environment variables with information about your Web App/Function App running on Azure.
You can use WEBSITE_INSTANCE_ID
to get the id of instance hosting your Function App
public static class TestFunction
{
[FunctionName("TestFunction")]
public static void Run([TimerTrigger("0 */5 * * * *")]TimerInfo myTimer, ILogger log)
{
log.LogInformation(Environment.GetEnvironmentVariable("WEBSITE_INSTANCE_ID"));
}
}
Reference: https://github.com/projectkudu/kudu/wiki/Azure-runtime-environment#environment
Upvotes: 2