Azure Functions 2.x 及更高版本的 host.json 参考host.json reference for Azure Functions 2.x and later

host.json 元数据文件包含对函数应用的所有函数产生影响的全局配置选项。The host.json metadata file contains global configuration options that affect all functions for a function app. 本文列出了从 Azure Functions 运行时 2.x 版开始可用的设置。This article lists the settings that are available starting with version 2.x of the Azure Functions runtime.

备注

本文适用于 Azure Functions 2.x 及更高版本。This article is for Azure Functions 2.x and later versions. 有关 Functions 1.x 中 host.json 的参考,请参阅 Azure Functions 1.x 的 host.json 参考For a reference of host.json in Functions 1.x, see host.json reference for Azure Functions 1.x.

其他函数应用配置选项在应用设置(适用于已部署的应用)或 local.settings.json 文件(用于本地开发)中进行管理。Other function app configuration options are managed in your app settings (for deployed apps) or your local.settings.json file (for local development).

host.json 中与绑定相关的配置将同样地应用于函数应用中的每个函数。Configurations in host.json related to bindings are applied equally to each function in the function app.

还可以使用应用程序设置来按环境覆盖或应用设置You can also override or apply settings per environment using application settings.

示例 host.json 文件Sample host.json file

以下版本 2.x+ 的示例 host.json 文件指定了所有可能的选项(不包括仅供内部使用的任何选项)。The following sample host.json file for version 2.x+ has all possible options specified (excluding any that are for internal use only).

{
    "version": "2.0",
    "aggregator": {
        "batchSize": 1000,
        "flushTimeout": "00:00:30"
    },
    "extensions": {
        "cosmosDb": {},
        "durableTask": {},
        "eventHubs": {},
        "http": {},
        "queues": {},
        "sendGrid": {},
        "serviceBus": {}
    },
    "extensionBundle": {
        "id": "Microsoft.Azure.Functions.ExtensionBundle",
        "version": "[1.*, 2.0.0)"
    },
    "functions": [ "QueueProcessor", "GitHubWebHook" ],
    "functionTimeout": "00:05:00",
    "healthMonitor": {
        "enabled": true,
        "healthCheckInterval": "00:00:10",
        "healthCheckWindow": "00:02:00",
        "healthCheckThreshold": 6,
        "counterThreshold": 0.80
    },
    "logging": {
        "fileLoggingMode": "debugOnly",
        "logLevel": {
          "Function.MyFunction": "Information",
          "default": "None"
        },
        "applicationInsights": {
            "samplingSettings": {
              "isEnabled": true,
              "maxTelemetryItemsPerSecond" : 20,
              "evaluationInterval": "01:00:00",
              "initialSamplingPercentage": 100.0, 
              "samplingPercentageIncreaseTimeout" : "00:00:01",
              "samplingPercentageDecreaseTimeout" : "00:00:01",
              "minSamplingPercentage": 0.1,
              "maxSamplingPercentage": 100.0,
              "movingAverageRatio": 1.0,
              "excludedTypes" : "Dependency;Event",
              "includedTypes" : "PageView;Trace"
            },
            "enableLiveMetrics": true,
            "enableDependencyTracking": true,
            "enablePerformanceCountersCollection": true,            
            "httpAutoCollectionOptions": {
                "enableHttpTriggerExtendedInfoCollection": true,
                "enableW3CDistributedTracing": true,
                "enableResponseHeaderInjection": true
            },
            "snapshotConfiguration": {
                "agentEndpoint": null,
                "captureSnapshotMemoryWeight": 0.5,
                "failedRequestLimit": 3,
                "handleUntrackedExceptions": true,
                "isEnabled": true,
                "isEnabledInDeveloperMode": false,
                "isEnabledWhenProfiling": true,
                "isExceptionSnappointsEnabled": false,
                "isLowPrioritySnapshotUploader": true,
                "maximumCollectionPlanSize": 50,
                "maximumSnapshotsRequired": 3,
                "problemCounterResetInterval": "24:00:00",
                "provideAnonymousTelemetry": true,
                "reconnectInterval": "00:15:00",
                "shadowCopyFolder": null,
                "shareUploaderProcess": true,
                "snapshotInLowPriorityThread": true,
                "snapshotsPerDayLimit": 30,
                "snapshotsPerTenMinutesLimit": 1,
                "tempFolder": null,
                "thresholdForSnapshotting": 1,
                "uploaderProxy": null
            }
        }
    },
    "managedDependency": {
        "enabled": true
    },
    "singleton": {
      "lockPeriod": "00:00:15",
      "listenerLockPeriod": "00:01:00",
      "listenerLockRecoveryPollingInterval": "00:01:00",
      "lockAcquisitionTimeout": "00:01:00",
      "lockAcquisitionPollingInterval": "00:00:03"
    },
    "watchDirectories": [ "Shared", "Test" ]
}

本文的以下各部分解释了每个顶级属性。The following sections of this article explain each top-level property. 除非另有说明,否则其中的所有属性都是可选的。All are optional unless otherwise indicated.

aggregatoraggregator

指定在计算 Application Insights 的指标时要聚合多少个函数调用。Specifies how many function invocations are aggregated when calculating metrics for Application Insights.

{
    "aggregator": {
        "batchSize": 1000,
        "flushTimeout": "00:00:30"
    }
}
属性Property 默认Default 说明Description
batchSizebatchSize 10001000 要聚合的最大请求数。Maximum number of requests to aggregate.
flushTimeoutflushTimeout 00:00:3000:00:30 要聚合的最大时间段。Maximum time period to aggregate.

达到两个限制中的第一个限制时,会聚合函数调用。Function invocations are aggregated when the first of the two limits are reached.

applicationInsightsapplicationInsights

此设置是日志记录的子项。This setting is a child of logging.

Application Insights 的控制选项,包括采样选项Controls options for Application Insights, including sampling options.

若要了解完整的 JSON 结构,请参阅前面的示例 host.json 文件For the complete JSON structure, see the earlier example host.json file.

备注

日志采样可能会导致一些执行不会显示在 Application Insights 监视器边栏选项卡中。Log sampling may cause some executions to not show up in the Application Insights monitor blade. 若要避免日志采样,请将 excludedTypes: "Request" 添加到 samplingSettings 值。To avoid log sampling, add excludedTypes: "Request" to the samplingSettings value.

属性Property 默认Default 说明Description
samplingSettingssamplingSettings 不适用n/a 请参阅 applicationInsights.samplingSettingsSee applicationInsights.samplingSettings.
enableLiveMetricsenableLiveMetrics truetrue 启用实时指标收集。Enables live metrics collection.
enableDependencyTrackingenableDependencyTracking truetrue 自定义依赖项跟踪。Enables dependency tracking.
enablePerformanceCountersCollectionenablePerformanceCountersCollection truetrue 启用 Kudu 性能计数器收集。Enables Kudu performance counters collection.
liveMetricsInitializationDelayliveMetricsInitializationDelay 00:00:1500:00:15 仅限内部使用。For internal use only.
httpAutoCollectionOptionshttpAutoCollectionOptions 不适用n/a 请参阅 applicationInsights.httpAutoCollectionOptionsSee applicationInsights.httpAutoCollectionOptions.
snapshotConfigurationsnapshotConfiguration 不适用n/a 请参阅 applicationInsights.snapshotConfigurationSee applicationInsights.snapshotConfiguration.

applicationInsights.samplingSettingsapplicationInsights.samplingSettings

属性Property 默认Default 说明Description
isEnabledisEnabled truetrue 启用或禁用采样。Enables or disables sampling.
maxTelemetryItemsPerSecondmaxTelemetryItemsPerSecond 2020 每个服务器主机上每秒记录的遥测项的目标数目。The target number of telemetry items logged per second on each server host. 如果应用在多个主机上运行,请将此值降低至总体目标流量率的范围内。If your app runs on many hosts, reduce this value to remain within your overall target rate of traffic.
evaluationIntervalevaluationInterval 01:00:0001:00:00 会重新评估当前遥测速率的间隔。The interval at which the current rate of telemetry is reevaluated. 评估以移动平均线形式进行执行。Evaluation is performed as a moving average. 可能想要缩短此间隔(如果遥测很容易就激增)。You might want to shorten this interval if your telemetry is liable to sudden bursts.
initialSamplingPercentageinitialSamplingPercentage 100.0100.0 采样过程开始时应用的初始采样百分比,以动态改变百分比。The initial sampling percentage applied at the start of the sampling process to dynamically vary the percentage. 不要在调试时减小值。Don't reduce value while you're debugging.
samplingPercentageIncreaseTimeoutsamplingPercentageIncreaseTimeout 00:00:0100:00:01 采样百分比值更改时,此属性确定多久之后允许 Application Insights 再次提升采样百分比以捕获更多数据。When the sampling percentage value changes, this property determines how soon afterwards Application Insights is allowed to raise sampling percentage again to capture more data.
samplingPercentageDecreaseTimeoutsamplingPercentageDecreaseTimeout 00:00:0100:00:01 采样百分比值更改时,此属性确定多久之后允许 Application Insights 再次降低采样百分比以捕获更少数据。When the sampling percentage value changes, this property determines how soon afterwards Application Insights is allowed to lower sampling percentage again to capture less data.
minSamplingPercentageminSamplingPercentage 0.10.1 随着采样百分比变化,此属性确定允许的最小采样百分比。As sampling percentage varies, this property determines the minimum allowed sampling percentage.
maxSamplingPercentagemaxSamplingPercentage 100.0100.0 随着采样百分比变化,此属性确定允许的最大采样百分比。As sampling percentage varies, this property determines the maximum allowed sampling percentage.
movingAverageRatiomovingAverageRatio 1.01.0 在移动平均线的计算中,权重分配给最新的值。In the calculation of the moving average, the weight assigned to the most recent value. 使用等于或小于 1 的值。Use a value equal to or less than 1. 较小的值会使算法不易受突然的更改影响。Smaller values make the algorithm less reactive to sudden changes.
excludedTypesexcludedTypes nullnull 不要采样的分号分隔类型列表。A semi-colon delimited list of types that you don't want to be sampled. 承认的类型为:DependencyEventExceptionPageViewRequestTraceRecognized types are: Dependency, Event, Exception, PageView, Request, and Trace. 指定类型的所有实例都会传输;对未指定的类型进行采样。All instances of the specified types are transmitted; the types that aren't specified are sampled.
includedTypesincludedTypes nullnull 要采样的分号分隔类型列表;空列表暗示所有类型。A semi-colon delimited list of types that you want to be sampled; an empty list implies all types. excludedTypes 中列出的类型替代此处列出的类型。Type listed in excludedTypes override types listed here. 承认的类型为:DependencyEventExceptionPageViewRequestTraceRecognized types are: Dependency, Event, Exception, PageView, Request, and Trace. 指定类型的实例都会采样;未指定或未暗示的类型将进行传输而不采样。Instances of the specified types are sampled; the types that aren't specified or implied are transmitted without sampling.

applicationInsights.httpAutoCollectionOptionsapplicationInsights.httpAutoCollectionOptions

属性Property 默认Default 说明Description
enableHttpTriggerExtendedInfoCollectionenableHttpTriggerExtendedInfoCollection truetrue 启用或禁用 HTTP 触发器的扩展 HTTP 请求信息:传入请求关联标头、多检测密钥支持、HTTP 方法、路径及响应。Enables or disables extended HTTP request information for HTTP triggers: incoming request correlation headers, multi-instrumentation keys support, HTTP method, path, and response.
enableW3CDistributedTracingenableW3CDistributedTracing truetrue 启用或禁用对 W3C 分布式跟踪协议的支持(并开启旧版关联架构)。Enables or disables support of W3C distributed tracing protocol (and turns on legacy correlation schema). 如果 enableHttpTriggerExtendedInfoCollection 为 true,则默认启用。Enabled by default if enableHttpTriggerExtendedInfoCollection is true. 如果 enableHttpTriggerExtendedInfoCollection 为 false,则此标志仅适用于传出请求,而不适用于传入请求。If enableHttpTriggerExtendedInfoCollection is false, this flag applies to outgoing requests only, not incoming requests.
enableResponseHeaderInjectionenableResponseHeaderInjection truetrue 启用或禁用将多组件关联标头注入响应。Enables or disables injection of multi-component correlation headers into responses. 启用注入将在使用多个检测密钥时允许 Application Insights 构造应用程序映射。Enabling injection allows Application Insights to construct an Application Map to when several instrumentation keys are used. 如果 enableHttpTriggerExtendedInfoCollection 为 true,则默认启用。Enabled by default if enableHttpTriggerExtendedInfoCollection is true. 如果 enableHttpTriggerExtendedInfoCollection 为 false,则此设置不适用。This setting doesn't apply if enableHttpTriggerExtendedInfoCollection is false.

applicationInsights.snapshotConfigurationapplicationInsights.snapshotConfiguration

有关快照的详细信息,请参阅 .NET 应用中发生异常时调试快照排查启用 Application Insights Snapshot Debugger 或查看快照时遇到的问题For more information on snapshots, see Debug snapshots on exceptions in .NET apps and Troubleshoot problems enabling Application Insights Snapshot Debugger or viewing snapshots.

属性Property 默认Default 说明Description
agentEndpointagentEndpoint nullnull 用于连接到 Application Insights Snapshot Debugger 服务的终结点。The endpoint used to connect to the Application Insights Snapshot Debugger service. 如果为 null,则使用默认终结点。If null, a default endpoint is used.
captureSnapshotMemoryWeightcaptureSnapshotMemoryWeight 0.50.5 检查是否有足够内存来拍摄快照时,为当前进程内存大小指定的权重。The weight given to the current process memory size when checking if there's enough memory to take a snapshot. 预期值为大于 0 的正确分数 (0 < CaptureSnapshotMemoryWeight < 1)。The expected value is a greater than 0 proper fraction (0 < CaptureSnapshotMemoryWeight < 1).
failedRequestLimitfailedRequestLimit 33 禁用遥测处理器之前请求快照的失败请求数限制。The limit on the number of failed requests to request snapshots before the telemetry processor is disabled.
handleUntrackedExceptionshandleUntrackedExceptions truetrue 启用或禁用不由 Application Insights 遥测跟踪的异常跟踪。Enables or disables tracking of exceptions that aren't tracked by Application Insights telemetry.
isEnabledisEnabled truetrue 启用或禁用快照收集Enables or disables snapshot collection
isEnabledInDeveloperModeisEnabledInDeveloperMode falsefalse 启用或禁用在开发人员模式下启用快照收集。Enables or disables snapshot collection is enabled in developer mode.
isEnabledWhenProfilingisEnabledWhenProfiling truetrue 启用或禁用快照创建,即使 Application Insights Profiler 正在收集详细的分析会话。Enables or disables snapshot creation even if the Application Insights Profiler is collecting a detailed profiling session.
isExceptionSnappointsEnabledisExceptionSnappointsEnabled falsefalse 启用或禁用异常筛选。Enables or disables filtering of exceptions.
isLowPrioritySnapshotUploaderisLowPrioritySnapshotUploader truetrue 确定是否使用低于正常优先级运行 SnapshotUploader 进程。Determines whether to run the SnapshotUploader process at below normal priority.
maximumCollectionPlanSizemaximumCollectionPlanSize 5050 在任何时候可以跟踪的最大问题数,范围为 1 到 9999。The maximum number of problems that we can track at any time in a range from one to 9999.
maximumSnapshotsRequiredmaximumSnapshotsRequired 33 为单个问题收集的最大快照数,范围为 1 到 999。The maximum number of snapshots collected for a single problem, in a range from one to 999. 应用程序中可将问题视为单个 throw 语句。A problem may be thought of as an individual throw statement in your application. 为问题收集的快照数达到此值后,将不再为该问题收集更多的快照直到重置问题计数器(请参阅 problemCounterResetInterval)并再次达到 thresholdForSnapshotting 限制。Once the number of snapshots collected for a problem reaches this value, no more snapshots will be collected for that problem until problem counters are reset (see problemCounterResetInterval) and the thresholdForSnapshotting limit is reached again.
problemCounterResetIntervalproblemCounterResetInterval 24:00:0024:00:00 重置问题计数器的频率,范围为一分钟到七天。How often to reset the problem counters in a range from one minute to seven days. 达到此间隔时间后,所有问题计数都将重置为零。When this interval is reached, all problem counts are reset to zero. 已达到拍摄快照的阈值但尚未在 maximumSnapshotsRequired 中生成快照数的现有问题仍处于活动状态。Existing problems that have already reached the threshold for doing snapshots, but haven't yet generated the number of snapshots in maximumSnapshotsRequired, remain active.
provideAnonymousTelemetryprovideAnonymousTelemetry truetrue 确定是否将匿名使用情况和错误的遥测数据发送给 Microsoft。Determines whether to send anonymous usage and error telemetry to Microsoft. 如果与 Microsoft 联系以通过 Snapshot Debugger 帮助解决问题,则可以使用此遥测数据。This telemetry may be used if you contact Microsoft to help troubleshoot problems with the Snapshot Debugger. 它还用于监视使用模式。It is also used to monitor usage patterns.
reconnectIntervalreconnectInterval 00:15:0000:15:00 重新连接到 Snapshot Debugger 终结点的频率。How often we reconnect to the Snapshot Debugger endpoint. 允许的范围是一分钟到一天。Allowable range is one minute to one day.
shadowCopyFoldershadowCopyFolder nullnull 指定用于影子副本二进制文件的文件夹。Specifies the folder to use for shadow copying binaries. 如未设置,则按顺序尝试下列环境变量指定的文件夹:Fabric_Folder_App_Temp、LOCALAPPDATA、APPDATA、TEMP。If not set, the folders specified by the following environment variables are tried in order: Fabric_Folder_App_Temp, LOCALAPPDATA, APPDATA, TEMP.
shareUploaderProcessshareUploaderProcess truetrue 如果为 true,则只有一个 SnapshotUploader 实例将为共享 InstrumentationKey 的多个应用收集和上传快照。If true, only one instance of SnapshotUploader will collect and upload snapshots for multiple apps that share the InstrumentationKey. 如果设为 false,则 SnapshotUploader 对于每个 (ProcessName, InstrumentationKey) 元组都是唯一的。If set to false, the SnapshotUploader will be unique for each (ProcessName, InstrumentationKey) tuple.
snapshotInLowPriorityThreadsnapshotInLowPriorityThread truetrue 确定是否在低 IO 优先级线程中处理快照。Determines whether or not to process snapshots in a low IO priority thread. 创建快照是一个快速操作,但为了将快照上传到 Snapshot Debugger 服务,必须首先将其以小型转储的形式写入磁盘。Creating a snapshot is a fast operation but, in order to upload a snapshot to the Snapshot Debugger service, it must first be written to disk as a minidump. 这在 SnapshotUploader 进程中发生。That happens in the SnapshotUploader process. 如果将此值设为 true,则使用低优先级 IO 来写入小型转储,这不会与应用程序争用资源。Setting this value to true uses low-priority IO to write the minidump, which won't compete with your application for resources. 如果将此值设为 false,会加速创建小型转储,同时降低应用程序的运行速度。Setting this value to false speeds up minidump creation at the expense of slowing down your application.
snapshotsPerDayLimitsnapshotsPerDayLimit 3030 一天(24 小时)中允许的最大快照数。The maximum number of snapshots allowed in one day (24 hours). 此限制还强制用于 Application Insights 服务端。This limit is also enforced on the Application Insights service side. 上传速率限制为每个应用程序(即每个检测密钥)每天 50 个。Uploads are rate limited to 50 per day per application (that is, per instrumentation key). 此值有助于阻止创建在上传过程中最终会遭到拒绝的其他快照。This value helps prevent creating additional snapshots that will eventually be rejected during upload. 如果此值为零则完全删除限制,不建议这样做。A value of zero removes the limit entirely, which isn't recommended.
snapshotsPerTenMinutesLimitsnapshotsPerTenMinutesLimit 11 10 分钟内允许的最大快照数。The maximum number of snapshots allowed in 10 minutes. 尽管此值没有上限,但由于它可能影响应用程序性能,因此在生产工作负荷中谨慎增加它。Although there is no upper bound on this value, exercise caution increasing it on production workloads because it could impact the performance of your application. 创建快照会很快,但创建快照的小型转储并将其上传到 Snapshot Debugger 服务则慢得多,它将与应用程序争用资源(CPU 和 I/O)。Creating a snapshot is fast, but creating a minidump of the snapshot and uploading it to the Snapshot Debugger service is a much slower operation that will compete with your application for resources (both CPU and I/O).
tempFoldertempFolder nullnull 指定用于写入小型转储并上传日志文件的文件夹。Specifies the folder to write minidumps and uploader log files. 如未设置,则使用 %TEMP%\Dumps。If not set, then %TEMP%\Dumps is used.
thresholdForSnapshottingthresholdForSnapshotting 11 Application Insights 请求快照之前需要查看异常的次数。How many times Application Insights needs to see an exception before it asks for snapshots.
uploaderProxyuploaderProxy nullnull 替代 Snapshot Uploader 进程中使用的代理服务器。Overrides the proxy server used in the Snapshot Uploader process. 如果应用程序通过代理服务器连接到 Internet,则可能需要使用此设置。You may need to use this setting if your application connects to the internet via a proxy server. Snapshot Collector 在应用程序的进程内运行,并使用相同的代理设置。The Snapshot Collector runs within your application's process and will use the same proxy settings. 但是,Snapshot Uploader 作为单独的进程运行,并且你可能需要手动配置代理服务器。However, the Snapshot Uploader runs as a separate process and you may need to configure the proxy server manually. 如果此值为 null,Snapshot Collector 将尝试通过检查 System.Net.WebRequest.DefaultWebProxy 并将值传递到 Snapshot Uploader 来自动检测代理的地址。If this value is null, then Snapshot Collector will attempt to autodetect the proxy's address by examining System.Net.WebRequest.DefaultWebProxy and passing on the value to the Snapshot Uploader. 如果此值不为 null,则不会使用自动检测,并且将在 Snapshot Uploader 中使用此处指定的代理服务器。If this value isn't null, then autodetection isn't used and the proxy server specified here will be used in the Snapshot Uploader.

CosmosDBcosmosDb

可在 Cosmos DB 触发器和绑定中查找配置设置。Configuration setting can be found in Cosmos DB triggers and bindings.

durableTaskdurableTask

可在 Durable Functions 的绑定中查找配置设置。Configuration setting can be found in bindings for Durable Functions.

eventHubeventHub

可在事件中心触发器和绑定中查找配置设置。Configuration settings can be found in Event Hub triggers and bindings.

扩展extensions

返回包含所有特定于绑定的设置的对象的属性,例如 httpeventHubProperty that returns an object that contains all of the binding-specific settings, such as http and eventHub.

extensionBundleextensionBundle

使用扩展捆绑可将一组兼容的 Functions 绑定扩展添加到函数应用。Extension bundles let you add a compatible set of Functions binding extensions to your function app. 若要了解详细信息,请参阅用于本地开发的扩展捆绑To learn more, see Extension bundles for local development.

{
    "version": "2.0",
    "extensionBundle": {
        "id": "Microsoft.Azure.Functions.ExtensionBundle",
        "version": "[1.*, 2.0.0)"
    }
}

extensionBundle 中提供了以下属性:The following properties are available in extensionBundle:

propertiesProperty 说明Description
idid Azure Functions 扩展捆绑的命名空间。The namespace for Azure Functions extension bundles.
版本version 要安装的捆绑包的版本。The version of the bundle to install. Functions 运行时始终选取由版本范围或间隔定义的可允许最高版本。The Functions runtime always picks the maximum permissible version defined by the version range or interval. 上述版本值允许从 1.0.0 到(但不包括)2.0.0 的所有捆绑包版本。The version value above allows all bundle versions from 1.0.0 up to but not including 2.0.0. 有关详细信息,请参阅用于指定版本范围的间隔表示法For more information, see the interval notation for specifying version ranges.

functionsfunctions

作业主机运行的函数列表。A list of functions that the job host runs. 空数组表示运行所有函数。An empty array means run all functions. 仅供在本地运行时使用。Intended for use only when running locally. 在 Azure 的函数应用中,应改为按照如何在 Azure Functions 中禁用函数中的步骤禁用特定函数,而不是使用此设置。In function apps in Azure, you should instead follow the steps in How to disable functions in Azure Functions to disable specific functions rather than using this setting.

{
    "functions": [ "QueueProcessor", "GitHubWebHook" ]
}

functionTimeoutfunctionTimeout

指示所有函数的超时持续时间。Indicates the timeout duration for all functions. 它采用 timespan 字符串格式。It follows the timespan string format.

计划类型Plan type 默认值(分钟)Default (min) 最大值(分钟)Maximum (min)
消耗Consumption 55 1010
高级1Premium1 3030 -1(无限制)2-1 (unbounded)2
专用(应用服务)Dedicated (App Service) 3030 -1(无限制)2-1 (unbounded)2

1 高级计划执行只能保证 60 分钟,但技术上不限时长。1 Premium plan execution is only guaranteed for 60 minutes, but technically unbounded.
2 值为 -1 表示无限制执行,但建议保留固定上限。2 A value of -1 indicates unbounded execution, but keeping a fixed upper bound is recommended.

{
    "functionTimeout": "00:05:00"
}

healthMonitorhealthMonitor

主机运行状况监视器的配置设置。Configuration settings for Host health monitor.

{
    "healthMonitor": {
        "enabled": true,
        "healthCheckInterval": "00:00:10",
        "healthCheckWindow": "00:02:00",
        "healthCheckThreshold": 6,
        "counterThreshold": 0.80
    }
}
属性Property 默认Default 说明Description
enabledenabled true 指定是否已启用该功能。Specifies whether the feature is enabled.
healthCheckIntervalhealthCheckInterval 10 秒10 seconds 定期后台运行状况检查之间的时间间隔。The time interval between the periodic background health checks.
healthCheckWindowhealthCheckWindow 2 分钟2 minutes healthCheckThreshold 设置结合使用的滑动时间窗口。A sliding time window used in conjunction with the healthCheckThreshold setting.
healthCheckThresholdhealthCheckThreshold 66 在启动主机回收之前,运行状况检查可以失败的最大次数。Maximum number of times the health check can fail before a host recycle is initiated.
counterThresholdcounterThreshold 0.800.80 性能计数器将被视为不正常的阈值。The threshold at which a performance counter will be considered unhealthy.

httphttp

可在 http 触发器和绑定中查找配置设置。Configuration settings can be found in http triggers and bindings.

日志记录logging

控制函数应用(包括 Application Insights)的日志记录行为。Controls the logging behaviors of the function app, including Application Insights.

"logging": {
    "fileLoggingMode": "debugOnly",
    "logLevel": {
      "Function.MyFunction": "Information",
      "default": "None"
    },
    "console": {
        ...
    },
    "applicationInsights": {
        ...
    }
}
属性Property 默认Default 说明Description
fileLoggingModefileLoggingMode debugOnlydebugOnly 定义启用哪种级别的文件日志记录。Defines what level of file logging is enabled. 选项包括 neveralwaysdebugOnlyOptions are never, always, debugOnly.
logLevellogLevel 不适用n/a 一个对象,它定义了用于筛选应用中的函数的日志类别。Object that defines the log category filtering for functions in the app. 2.x 及更高版本遵循 ASP.NET Core 布局进行日志类别筛选。Versions 2.x and later follow the ASP.NET Core layout for log category filtering. 此设置允许你筛选特定函数的日志记录。This setting lets you filter logging for specific functions. 有关详细信息,请参阅 ASP.NET Core 文档中的日志筛选For more information, see Log filtering in the ASP.NET Core documentation.
控制台console 不适用n/a 控制台日志记录设置。The console logging setting.
applicationInsightsapplicationInsights 不适用n/a applicationInsights 设置。The applicationInsights setting.

控制台console

此设置是日志记录的子项。This setting is a child of logging. 它在未处于调试模式时控制控制台日志记录。It controls the console logging when not in debugging mode.

{
    "logging": {
    ...
        "console": {
          "isEnabled": "false"
        },
    ...
    }
}
属性Property 默认Default 说明Description
isEnabledisEnabled falsefalse 启用或禁用控制台日志记录。Enables or disables console logging.

managedDependencymanagedDependency

托管依赖项是一项功能,目前仅支持基于 PowerShell 的函数。Managed dependency is a feature that is currently only supported with PowerShell based functions. 它使依赖项可以由服务自动管理。It enables dependencies to be automatically managed by the service. enabled 属性设置为 true 时,requirements.psd1 文件会被处理。When the enabled property is set to true, the requirements.psd1 file is processed. 发布任何次要版本时会更新依赖项。Dependencies are updated when any minor versions are released.

{
    "managedDependency": {
        "enabled": true
    }
}

queuesqueues

可在存储队列触发器和绑定中查找设置。Configuration settings can be found in Storage queue triggers and bindings.

SendGridsendGrid

可在 SendGrid 触发器和绑定中查找配置设置。Configuration setting can be found in SendGrid triggers and bindings.

serviceBusserviceBus

可在服务总线触发器和绑定中查找配置设置。Configuration setting can be found in Service Bus triggers and bindings.

singletonsingleton

单一实例锁行为的配置设置。Configuration settings for Singleton lock behavior. 有关详细信息,请参阅有关单一实例支持的 GitHub 问题For more information, see GitHub issue about singleton support.

{
    "singleton": {
      "lockPeriod": "00:00:15",
      "listenerLockPeriod": "00:01:00",
      "listenerLockRecoveryPollingInterval": "00:01:00",
      "lockAcquisitionTimeout": "00:01:00",
      "lockAcquisitionPollingInterval": "00:00:03"
    }
}
属性Property 默认Default 说明Description
lockPeriodlockPeriod 00:00:1500:00:15 占用函数级锁的时间段。The period that function level locks are taken for. 锁自动续订。The locks auto-renew.
listenerLockPeriodlistenerLockPeriod 00:01:0000:01:00 占用侦听器锁的时间段。The period that listener locks are taken for.
listenerLockRecoveryPollingIntervallistenerLockRecoveryPollingInterval 00:01:0000:01:00 在启动时无法获取侦听器锁的情况下,用于恢复侦听器锁的时间间隔。The time interval used for listener lock recovery if a listener lock couldn't be acquired on startup.
lockAcquisitionTimeoutlockAcquisitionTimeout 00:01:0000:01:00 运行时尝试获取锁的最长时间。The maximum amount of time the runtime will try to acquire a lock.
lockAcquisitionPollingIntervallockAcquisitionPollingInterval 不适用n/a 尝试获取锁的间隔时间。The interval between lock acquisition attempts.

版本version

此值指示 host.json 的架构版本。This value indicates the schema version of host.json. 面向 v2 运行时或更高版本的函数应用需要版本字符串 "version": "2.0"The version string "version": "2.0" is required for a function app that targets the v2 runtime, or a later version. v2 和 v3 之间没有 host.json 架构更改。There are no host.json schema changes between v2 and v3.

watchDirectorieswatchDirectories

应该监视其更改情况的一组共享代码目录A set of shared code directories that should be monitored for changes. 确保当这些目录中的代码发生更改时,函数会拾取这些更改。Ensures that when code in these directories is changed, the changes are picked up by your functions.

{
    "watchDirectories": [ "Shared" ]
}

重写 host.json 值Override host.json values

某些情况下,可能希望为特定环境配置或修改 host.json 文件中的特定设置,而无需更改 host.json 文件本身。There may be instances where you wish to configure or modify specific settings in a host.json file for a specific environment, without changing the host.json file itself. 可以通过创建等效值作为应用程序设置来重写特定的 host.json 值。You can override specific host.json values be creating an equivalent value as an application setting. 当运行时查找 AzureFunctionsJobHost__path__to__setting 格式的应用程序设置时,它将重写 JSON 中位于 path.to.setting 的等效 host.json 设置。When the runtime finds an application setting in the format AzureFunctionsJobHost__path__to__setting, it overrides the equivalent host.json setting located at path.to.setting in the JSON. 当表示为应用程序设置时,用于指示 JSON 层次结构的点 (.) 将替换为双下划线 (__)。When expressed as an application setting, the dot (.) used to indicate JSON hierarchy is replaced by a double underscore (__).

假设当 Application insights 在本地运行时想要禁用 Application insights 采样。For example, say that you wanted to disable Application Insight sampling when running locally. 如果更改了本地 host.json 文件以禁用 Application Insights,则在部署过程中可能将此更改推送到生产应用。If you changed the local host.json file to disable Application Insights, this change might get pushed to your production app during deployment. 执行此操作更为安全的方法是创建应用程序设置作为 local.settings.json 文件中的 "AzureFunctionsJobHost__logging__applicationInsights__samplingSettings__isEnabled":"false"The safer way to do this is to instead create an application setting as "AzureFunctionsJobHost__logging__applicationInsights__samplingSettings__isEnabled":"false" in the local.settings.json file. 可以在以下 local.settings.json 文件中查看此内容,但这不会发布:You can see this in the following local.settings.json file, which doesn't get published:

{
    "IsEncrypted": false,
    "Values": {
        "AzureWebJobsStorage": "{storage-account-connection-string}",
        "FUNCTIONS_WORKER_RUNTIME": "{language-runtime}",
        "AzureFunctionsJobHost__logging__applicationInsights__samplingSettings__isEnabled":"false"
    }
}

后续步骤Next steps