Azure WebJob 应用程序洞察

Azure WebJob Application Insight

我们在 Azure Web api 站点中部署了一些 Web 作业。我们认为其中一个存在内存泄漏,但我们没有详细说明是什么原因造成的。因此,我想看看是否可以将 nuget 包添加到 application insights 中。 https://github.com/Azure/azure-webjobs-sdk/wiki/Application-Insights-Integration

当我尝试 运行 时,我得到如下错误

我的程序就是这样

class Program
{
    private static string ConnectionString { get; set; }
    private static readonly JobHostConfiguration _config = new JobHostConfiguration("DefaultEndpointsProtocol=https;AccountName=mcastagstorage;AccountKey=fW/DoBsghvPgEy2/uBTZSxSSvgPoUs/jGRxV59scXmexpfDSPbSGLovjAuoLtGbSIuDBobDHyIfUdHrWWRz5DA==;EndpointSuffix=core.windows.net");

    // Please set the following connection strings in app.config for this WebJob to run:
    // AzureWebJobsDashboard and AzureWebJobsStorage
    static void Main()
    {
        string instrumentationKey = "MyKey";
        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;
        }

        ConnectionString = ConfigurationManager.ConnectionStrings["ConsistingEntities"].ConnectionString;

        if (_config.IsDevelopment)
        {
            _config.UseDevelopmentSettings();
        }

        var host = new JobHost(_config);
        // The following code ensures that the WebJob will be running continuously
        host.RunAndBlock();
    }
}

LoaderExceptions如下

我对 .net 版本也很困惑,我习惯了原来的 .net 但现在看到 .net 标准和核心,不知道我应该为此使用什么 .net。

如有任何帮助,我们将不胜感激

我测试了你的代码并重现了你的问题。

您似乎正在使用 WebJobs v3。如果是这样,Newtonsoft.Json 的版本将为 10.0.3。

看了这个article没有说明这是webjob的bug。

我用下面的方法解决了,如果你不介意,你可以回到WebJobs v2 beta或者更新Newtonsoft.Json 到版本 < 10.0.3.