TraceWriter 日志未进入分析

TraceWriter logs not getting to analytics

我正在尝试为测试应用设置分析:

public void ProcessQueueMessage(
       [BlobTrigger("blob-injector/{name}")] CloudBlockBlob blob,
       string name,
       [Queue("invoice")] ICollector<string> output,
       [Blob("blob-archive/{name}")] CloudBlockBlob archive,
       TraceWriter log)
    {

        log.Info($"Started processing {name}");
        string content = blob.DownloadText();
        log.Info($"retrieved file {name}{Environment.NewLine}{content}");
        output.Add(content);
        log.Info($"{name} added to queue");
        archive.UploadText(content);
        log.Info($"{name} has been archived");
        blob.DeleteIfExists();
        log.Info($"Completed processing {name}");
    }

并且我已将一个 appInsights 实例添加到我的 azure 订阅中。我正在从应用程序服务中获取一些日志记录:

我将诊断日志记录设置为记录到 blob 存储,我可以在那里找到我的日志。我发现的所有信息似乎都表明我所拥有的就是我所需要的。但是我在 Application Insights 中找不到我的日志。

[编辑} 如果相关的话,这是一个 .net 4.6.1 WebJob。

[更新] 我已将其更改为使用 TelemetryClient 并使用它获取日志。

假设您正在使用 Microsoft.Azure.WebJobs.Logging.ApplicationInsights 2.2.0

我可以看到 TraceWriter 日志根据下面的 steps/code 进行分析:

1.Create .net framework 4.6.1 网络作业

2.In visual studio Nuget 包管理器,安装以下版本包:

Microsoft.Azure.WebJobs.Logging.ApplicationInsights 2.2.0

System.Configuration.ConfigurationManager 4.5.0

Microsoft.Extensions.Logging.Console 2.1.1

3.In app.config 文件,添加以下内容(本地测试):

AzureWebJobsDashboard, AzureWebJobsStorage, APPINSIGHTS_INSTRUMENTATIONKEY

屏幕截图如下所示:

4.In 你的 azure web 应用程序 -> 应用程序设置,添加 AzureWebJobsDashboardAPPINSIGHTS_INSTRUMENTATIONKEY,屏幕截图如下所示:

5.InMain()方法,添加如下代码:

using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Logging;
using System.Configuration;

namespace WebJob8
{    
    class Program
    {       
        static void Main()
        {
            using (var loggerFactory = new LoggerFactory())
            {
                var config = new JobHostConfiguration();

                var instrumentationKey = ConfigurationManager.AppSettings["APPINSIGHTS_INSTRUMENTATIONKEY"];
                config.DashboardConnectionString = "";
                config.LoggerFactory = loggerFactory
                    .AddApplicationInsights(instrumentationKey, null)
                    .AddConsole();

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

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

6.The 中的代码 Functions.cs:

    public class Functions
    {
        // This function will get triggered/executed when a new message is written 
        // on an Azure Queue called queue.
        public static void ProcessQueueMessage([QueueTrigger("queue")] string message, TraceWriter log)
        {
            log.Info("1113 this is a queue message: "+message);
            log.Info("1113 it is a test from azure web jobs!!!");
        }
    }

7.Publish web job to azure, 运行 it, 然后nav to azure portal -> your application insights -> search,可以看到日志信息:

它也出现在分析中: