1

在我的示例项目中,我使用 EventFlow 来收集我的诊断数据并输出到 ApplicationInsight。日志记录也是通过 ApplicationInsight 完成的。诊断数据显示在 ApplicationInsight 门户上,但所有遥测类型都显示为 TRACE(即使诊断发送的遥测类型为 REQUEST)。但如果我直接使用 ApplicationInsight 登录(没有 EventFlow),它将在 ApplicationInsight 中正确显示正确的遥测类型。下面是我使用的 EventFlow 配置文件和示例代码。

顺便说一下,我的示例应用程序是 ASP.NET Core2 Web API。

eventFlowConfig.json

{

   "inputs": [
           { "type": "ApplicationInsights" }
  ],
  "outputs": [
    // Please update the instrumentationKey.
    {
      "type": "ApplicationInsights",
      "instrumentationKey": "xxxxxxxxxxx"
    }
  ],
  "schemaVersion": "2016-08-11"
}

示例代码

public void ConfigureServices(IServiceCollection services)
        {
            services.AddApplicationInsightsTelemetry();
            services.AddApplicationInsightsTelemetryProcessor<EventFlowTelemetryProcessor>();
            services.AddMvc();
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            var telemetryConfiguration = app.ApplicationServices.GetService<TelemetryConfiguration>();
            var eventFlowTelmetryProcessor = (EventFlowTelemetryProcessor)telemetryConfiguration
                                                .TelemetryProcessors
                                                .First(x => x.GetType() == typeof(EventFlowTelemetryProcessor));

            if (eventFlowTelmetryProcessor != null)
            {
                var diagnosticPipeline = app.ApplicationServices.GetService<DiagnosticPipeline>();
                eventFlowTelmetryProcessor.Pipeline = diagnosticPipeline;
            }

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseMvc();
        }

在这里,我附上了 ApplicationInsight 的屏幕截图以更清晰。这里它有一些遥测类型为 REQUEST 的诊断数据,但即使是那些也显示为 TRACE。

ApplicationInsight 屏幕截图

4

1 回答 1

0

发生这种情况是因为事件流AppInsights 输出使用TrackTrace处理所有输入事件\遥测,并且这些事件被发送到 ApplicationInsights 上的Trace表。

它还使用 AppInsights 事件类型(请求)来设置这些事件的 LogLevel,例如 Informational、Trace、Debug。

由于这种不必要的处理,您在前往目的地的途中会丢失一些东西。为什么不直接记录到 appInsights,而不是添加这个额外的开销来解析到 eventFlow,然后发送到 AppInsights?

于 2018-08-01T13:59:42.703 回答