How to check Azure function is running on local environment? `RoleEnvironment` is not working in Azure Functions

后端 未结 3 1727
庸人自扰
庸人自扰 2021-01-04 00:19

I have a condition in code where i need to check if current environment is not local.i have used !RoleEnvironment.IsEmulated, now this is not working in Azure

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-04 01:08

    You can use an approach similar to what the actual runtime uses to identify whether it is running on Azure: https://github.com/Azure/azure-webjobs-sdk-script/blob/efb55da/src/WebJobs.Script/Config/ScriptSettingsManager.cs#L25

    In this case, the runtime checks for the presence of an app setting named WEBSITE_INSTANCE_ID

提交回复
热议问题