我在local.settings.json
中有以下值
x1c 0d1x的数据
我在我的启动类中访问相同的,我为我的Azure函数添加了如下内容
public override void Configure(IFunctionsHostBuilder builder)
{
IConfiguration config;
var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
config = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddEnvironmentVariables()
.AddJsonFile($"local.settings.json", optional: true, reloadOnChange: true)
.Build();
builder.Services.Replace(ServiceDescriptor.Singleton(typeof(IConfiguration), config));
builder.Services.AddLogging();
var executionContextOptions = builder.Services.BuildServiceProvider()
.GetService<IOptions<ExecutionContextOptions>>().Value;
var currentDirectory = executionContextOptions.AppDirectory;
builder.Services.AddSingleton<IConfiguration>(config);
#region Serilog
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Information()
.MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
.MinimumLevel.Override("Worker", LogEventLevel.Warning)
.MinimumLevel.Override("Host", LogEventLevel.Warning)
.MinimumLevel.Override("System", LogEventLevel.Error)
.MinimumLevel.Override("Function", LogEventLevel.Error)
.MinimumLevel.Override("DurableTask", LogEventLevel.Error)
.MinimumLevel.Override("Azure.Storage.Blobs", LogEventLevel.Error)
.MinimumLevel.Override("Azure.Core", LogEventLevel.Error)
.MinimumLevel.Override("Azure.Messaging.ServiceBus", LogEventLevel.Error)
.Enrich.FromLogContext()
.WriteTo.Console()
.WriteTo.AzureAnalytics(config["AZURE_WORKSPACE_ID"],///<-***issue here///
config["AZURE_AUTHENTICATION_ID"])
.Enrich.WithEnvironmentName()
.CreateLogger();
builder.Services.AddLogging(lb => lb.AddSerilog(Log.Logger, true));
#endregion
}
字符串
它在本地工作正常,但在生产环境中,即使我在应用程序设置中有AZURE_WORKSPACE_ID
键,
的
我得到以下错误
Microsoft.Azure.WebJobs.Script.ExternalStartupException:在外部启动类中配置服务时出错。-> System.ArgumentNullException:值不能为空。(参数“workspaceId”)在Serilog. LoggerOperationExtensions.AzureAnalytics(LoggerSinkConfiguration loggerConfiguration,String workspaceId,String authenticationId,String logName,LogEventLevel restrictedToMinimumLevel,Boolean storeTimestampInUtc,IstampProvider formatProvider,Int32 logBufferSize,Int32 batchSize,AzureOfferingType azureOfferingType、LoggingLevelSwitch levelSwitch、Boolean对象、String代理)AZURE_WORKSPACE_ID
值未被拾取
1条答案
按热度按时间drkbr07n1#
这段代码在本地和Azure上都适用,如下所示:
我在
.NET 7 isolated
中创建了一个HTTP触发器函数,它从本地的local.settings.json
和Azure的app settings
中获取自定义环境变量。Program.cs
:字符串
Function1.cs
:型
本地环境
local.settings.json
型
Output
:的数据
的
Azure
的
Output
:的