使用Azure Web Job配置应用程序见解

时间:2019-04-24 13:05:16

标签: azure azure-webjobs

我正在尝试为我的webjob(Microsoft.Azure.Webjobs(v:2.3)配置Application Insights

if (!string.IsNullOrEmpty(instrumentationKey))
{
    // Wire up with default filters; Filtering will be explained later.
    config.LoggerFactory = new LoggerFactory()
                .AddApplicationInsights(instrumentationKey, null)
                .AddConsole();

    config.Tracing.ConsoleLevel = TraceLevel.Off;
}

loggerFactory不可用。

我已经在软件包下面安装了这些。

<package id="Microsoft.ApplicationInsights" version="2.4.0" targetFramework="net471" />
<package id="Microsoft.ApplicationInsights.Agent.Intercept" version="2.4.0" targetFramework="net471" />
<package id="Microsoft.ApplicationInsights.DependencyCollector" version="2.4.1" targetFramework="net471" />
<package id="Microsoft.ApplicationInsights.PerfCounterCollector" version="2.4.1" targetFramework="net471" />
<package id="Microsoft.ApplicationInsights.WindowsServer" version="2.4.1" targetFramework="net471" />
<package id="Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel" version="2.4.0" targetFramework="net471" />
<package id="Microsoft.Azure.WebJobs.Logging" version="3.0.6" targetFramework="net471" />
<package id="Microsoft.Azure.WebJobs.Logging.ApplicationInsights" version="2.3.0" targetFramework="net471" />

谢谢!

2 个答案:

答案 0 :(得分:2)

您已经安装了以下NuGet软件包:

  • Microsoft.Azure.WebJobs.Logging.ApplicationInsights
  • Microsoft.Extensions.Logging
  • Microsoft.Extensions.Logging.Console

看看here

答案 1 :(得分:0)

似乎缺少JobHostConfiguration var config = new JobHostConfiguration();

否则,您可以按照以下代码段进行配置

var builder = new HostBuilder().ConfigureLogging((context, b) =>
{
    b.AddConsole();

    // If the key exists in settings, use it to enable Application Insights.
    var instrumentationKey = context.Configuration["APPINSIGHTS_INSTRUMENTATIONKEY"];
    if (!string.IsNullOrEmpty(instrumentationKey))
    {
        b.AddApplicationInsights(o => o.InstrumentationKey = instrumentationKey);
    }
})