Hosting environment why is it set to Production, Difference between host.json and local.settings.json

"Hosting environment" on the console comes from the environment variable ASPNETCORE_ENVIRONMENT. When this variable is not set, it defaults to "Production".

It's set here: HostingEnvironment.cs

The reason behind this default is described in this github issue.

This variable is popular in dotnet core web apps, but it is not mentioned in official docs in Azure functions (I am not sure why). If you write a for loop and output all the environment variables to console from within a function, you will find that this variable is not set by default - neither in production, nor when running in Visual Studio.

If you wish to define this variable locally, you have a few different ways.

Setting the environment variable via command line:

setx ASPNETCORE_ENVIRONMENT "Development"

Defining this in Properties\launchSettings.json:

  "commandName": "Project",
  "environmentVariables": {
    "ASPNETCORE_ENVIRONMENT": "Development"
  }

Defining this in local.settings.json:

  "Values": {
    "ASPNETCORE_ENVIRONMENT": "Development"
  }

Note that this variable is not automatically defined to production when you publish your app to azure. You will have to define this variable in "Configuration" -> "Application Settings" in Azure portal.

In azure functions there appears to be another similar environment variable called AZURE_FUNCTIONS_ENVIRONMENT. This one is defined by default locally.

AZURE_FUNCTIONS_ENVIRONMENT = Development

This is not defined in production by default, and can be defined in the azure portal.

Difference between host.json and local.settings.json:

host.json is to configure pre-defined settings that function app infrastructure understands. It applies to both local and production environments. It doesn't allow custom settings though. local.settings.json on the other hand is useful for defining custom settings. host.json is committed into source control, but local.settings.json is usually left out of source control, and is considered to be a good location to store secrets and connection strings for development.

More details here about the differences: https://docs.microsoft.com/en-us/azure/azure-functions/functions-develop-vs#create-an-azure-functions-project (scroll to the end of that section)

host.json reference

local.settings.json reference


  1. You can add "ASPNETCORE_ENVIRONMENT": "Development" in the local.settings.json, to change the hosting environment:

enter image description here

  1. As you know, local.settings.json is just for local testing and will not be published to azure portal. For host.json(which will be published to azure), you can configure settings like loglevel(if you want to log) in azure portal. More details, please refer to this article of host.json.