我有一个ASP.NET Core 2.0应用程序,通过Serilog启用ApplicationInsights,使用Startup.cs中的以下内容
siteorigin_widgets_field_class_prefixes
DependencyINitializer如下所示:
TelemetryConfiguration.Active.TelemetryInitializers.Add(new DependencyInitializer(ServiceProvider.GetService<IHttpContextAccessor>()));
Log.Logger = new LoggerConfiguration()
.ReadFrom.Configuration(Configuration)
.CreateLogger();
使用调试器我发现 public class DependencyInitializer : ITelemetryInitializer
{
private readonly IHttpContextAccessor _contextAccessor;
public DependencyInitializer(IHttpContextAccessor contextAccessor)
{
_contextAccessor = contextAccessor;
}
public void Initialize(ITelemetry telemetry)
{
if (telemetry is DependencyTelemetry)
{
telemetry.Context.Properties.Add("RequestId", _contextAccessor.HttpContext.TraceIdentifier);
}
}
}
仅截取ITelemetryInitializer
和TraceTelemetry
。但是,ExceptionTelemetry
正在写入应用程序的内容。我真的需要增强DependencyTelemetry
字段,因为现在它看起来像这样:
{&#34; _MS.ProcessedByMetricExtractors&#34;:&#34;(姓名:&#39;依赖关系&#39;,Ver:&#39; 1.0&#39;)&#34;,&# 34; AspNetCoreEnvironment&#34;:&#34;生产&#34;&#34; DeveloperMode&#34;:&#34;真&#34;}
如何在将DependencyTelemetry对象发送到应用洞察之前拦截它们,以便我可以向其添加customDimensions?
我可以使用这样的中间件拦截请求:
customDimensions
这些属性被添加,所以我知道Serilog正在使用&#34;正常&#34;应用洞察机制。