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

后端 未结 3 1802
庸人自扰
庸人自扰 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:18

    You can use the AZURE_FUNCTIONS_ENVIRONMENT environment variable, which is set automatically in local development:

    Environment.GetEnvironmentVariable("AZURE_FUNCTIONS_ENVIRONMENT"); // set to "Development" locally
    

    Note that when deployed/published (i.e. Azure), you'd need to set the environment variable yourself (e.g. function app settings in Azure).

提交回复
热议问题