对 azure webjob .Net Core 2.0 的应用洞察 [英] Application Insights to azure webjob .Net Core 2.0

查看:31
本文介绍了对 azure webjob .Net Core 2.0 的应用洞察的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 azure webjob 中添加应用洞察遥测(Application Insights)?

How to add application insights telemetry (Application Insights) to azure webjob ?

推荐答案

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

With recently released WebJob SDK 3.0, you can add ApplicationInsights in the ConfigureLogging method

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 webjob .Net Core 2.0 的应用洞察的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆