gpt4 book ai didi

c# - Azure Functions : how do you read the settings in host. json 在运行时?

转载 作者:行者123 更新时间:2023-12-04 15:35:23 25 4
gpt4 key购买 nike

有没有办法在运行时读取host.json文件中的主机设置?假设您有一个如下所示的主机文件:

{
"version": "2.0",
"extensions": {
"serviceBus": {
"messageHandlerOptions": {
"maxConcurrentCalls": 16
}
}
}
}

如何从 C# 代码中读取 maxConcurrentCalls 设置?

如果也包含默认值那就更好了。您应该获得与启动时在控制台中打印的相同的值:

[28-01-2020 09:16:06] LoggerFilterOptions
[28-01-2020 09:16:06] {
[28-01-2020 09:16:06] "MinLevel": "None",
[28-01-2020 09:16:06] "Rules": [
[28-01-2020 09:16:06] {
[28-01-2020 09:16:06] "ProviderName": null,
[28-01-2020 09:16:06] "CategoryName": null,
[28-01-2020 09:16:06] "LogLevel": null,
[28-01-2020 09:16:06] "Filter": "<AddFilter>b__0"
[28-01-2020 09:16:06] },
[28-01-2020 09:16:06] {
[28-01-2020 09:16:06] "ProviderName": "Microsoft.Azure.WebJobs.Script.WebHost.Diagnostics.SystemLoggerProvider",
[28-01-2020 09:16:06] "CategoryName": null,
[28-01-2020 09:16:06] "LogLevel": "None",
[28-01-2020 09:16:06] "Filter": null
[28-01-2020 09:16:06] },
[28-01-2020 09:16:06] {
[28-01-2020 09:16:06] "ProviderName": "Microsoft.Azure.WebJobs.Script.WebHost.Diagnostics.SystemLoggerProvider",
[28-01-2020 09:16:06] "CategoryName": null,
[28-01-2020 09:16:06] "LogLevel": null,
[28-01-2020 09:16:06] "Filter": "<AddFilter>b__0"
[28-01-2020 09:16:06] }
[28-01-2020 09:16:06] ]
[28-01-2020 09:16:06] }
[28-01-2020 09:16:06] FunctionResultAggregatorOptions
[28-01-2020 09:16:06] {
[28-01-2020 09:16:06] "BatchSize": 1000,
[28-01-2020 09:16:06] "FlushTimeout": "00:00:30",
[28-01-2020 09:16:06] "IsEnabled": true
[28-01-2020 09:16:06] }
[28-01-2020 09:16:06] SingletonOptions
[28-01-2020 09:16:06] {
[28-01-2020 09:16:06] "LockPeriod": "00:00:15",
[28-01-2020 09:16:06] "ListenerLockPeriod": "00:00:15",
[28-01-2020 09:16:06] "LockAcquisitionTimeout": "10675199.02:48:05.4775807",
[28-01-2020 09:16:06] "LockAcquisitionPollingInterval": "00:00:05",
[28-01-2020 09:16:06] "ListenerLockRecoveryPollingInterval": "00:01:00"
[28-01-2020 09:16:06] }
[28-01-2020 09:16:06] ServiceBusOptions
[28-01-2020 09:16:06] {
[28-01-2020 09:16:06] "PrefetchCount": 0,
[28-01-2020 09:16:06] "MessageHandlerOptions": {
[28-01-2020 09:16:06] "AutoComplete": true,
[28-01-2020 09:16:06] "MaxAutoRenewDuration": "00:05:00",
[28-01-2020 09:16:06] "MaxConcurrentCalls": 192
[28-01-2020 09:16:06] },
[28-01-2020 09:16:06] "SessionHandlerOptions": {
[28-01-2020 09:16:06] "AutoComplete": true,
[28-01-2020 09:16:06] "MaxAutoRenewDuration": "00:05:00",
[28-01-2020 09:16:06] "MaxConcurrentSessions": 2000,
[28-01-2020 09:16:06] "MessageWaitTimeout": "00:01:00"
[28-01-2020 09:16:06] },
[28-01-2020 09:16:06] "BatchOptions": {
[28-01-2020 09:16:06] "MaxMessageCount": 1000,
[28-01-2020 09:16:06] "OperationTimeout": "00:01:00",
[28-01-2020 09:16:06] "AutoComplete": true
[28-01-2020 09:16:06] }
[28-01-2020 09:16:06] }
[28-01-2020 09:16:06] HttpOptions
[28-01-2020 09:16:06] {
[28-01-2020 09:16:06] "DynamicThrottlesEnabled": false,
[28-01-2020 09:16:06] "MaxConcurrentRequests": -1,
[28-01-2020 09:16:06] "MaxOutstandingRequests": -1,
[28-01-2020 09:16:06] "RoutePrefix": "api"
[28-01-2020 09:16:06] }

最佳答案

这对我有用:

public class Startup : FunctionsStartup
{
public override void Configure(IFunctionsHostBuilder builder)
{
var config = builder.GetContext().Configuration;
string maxConcurrentCalls = config.GetSection("AzureFunctionsJobHost:extensions:serviceBus:messageHandlerOptions:maxConcurrentCalls").Value;
}
}

关于c# - Azure Functions : how do you read the settings in host. json 在运行时?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59945425/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com