Search code examples
c#azureazure-application-insightswebjob

Azure WebJob Application Insight


We have some web jobs deployed in an azure web api site. We believe one of these has a memory leak, but we have not details of what is causing it. I therefore wanted to see if I could add the nuget package to application insights. https://github.com/Azure/azure-webjobs-sdk/wiki/Application-Insights-Integration

When I try and run it I just get an error as follows

enter image description here My program is just this

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();
    }
}

The LoaderExceptions are as follows

enter image description here

I am very confused by the .net versions too, I am used to the original .net but now seeing .net standard and core, not sure what .net I am supposed to use for this.

Any help would be greatly appreciated


Solution

  • I tested your code and reproduced your problem.

    It looks like that you are using WebJobs v3. If so, the version of Newtonsoft.Json would be 10.0.3.

    It did not show that this is a bug in webjob after reading this article.

    I use the following methods to solve it, if you do not mind, you could go back to the WebJobs v2 beta or update the Newtonsoft.Json to version < 10.0.3.