gpt4 book ai didi

azure - azure webjob .Net Core 2.0 的应用程序见解

转载 作者:行者123 更新时间:2023-12-04 20:28:26 25 4
gpt4 key购买 nike

如何将应用程序洞察遥测(Application Insights)添加到azure webjob?

最佳答案

通过最近发布的 WebJob SDK 3.0,您可以在 ConfigureLogging 方法中添加 ApplicationInsights

public static async Task Main(string[] args)
{
var builder = new HostBuilder()
.ConfigureWebJobs(b =>
{
b.AddAzureStorageCoreServices().AddAzureStorage();
})
.ConfigureAppConfiguration(b =>
{
// Adding command line as a configuration source
b.AddCommandLine(args);
})
.ConfigureLogging((context, b) =>
{
b.SetMinimumLevel(LogLevel.Debug);
b.AddConsole();

// If this key exists in any config, use it to enable App Insights
string appInsightsKey = context.Configuration["ApplicationInsights:InstrumentationKey"];
if (!string.IsNullOrEmpty(appInsightsKey))
{
b.AddApplicationInsights(o => o.InstrumentationKey = appInsightsKey);
}
});

var host = builder.Build();
using (host)
{
await host.RunAsync();
}
}

关于azure - azure webjob .Net Core 2.0 的应用程序见解,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52424215/

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