在我的示例项目中,我使用 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。