ClientIpHeaderTelemetryInitializer和AspNetCore

编程入门 行业动态 更新时间:2024-10-27 19:18:58
本文介绍了ClientIpHeaderTelemetryInitializer和AspNetCore的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

Hello!

我一直在尝试建立一个演示,以使用AspNetCore应用程序上的Application Insights跟踪IP地址,我知道要实现这一点,您需要使用TelemetryInitializer,我打算使用随附的TelemetryInitializer. sdk ,但是所有文档都指向常规的ASP.NET

I have been trying to setup a demo to track IP addresses with Application Insights on an AspNetCore application, I know in order to achieve this you need to use a TelemetryInitializer I was intending to use the one included on the sdk, however all the documentation points to regular ASP.NET

能否请您提供一些有关如何使用AspNetCore启用这些初始化程序的指南?

Could you please provide some guidance on how these Initializers are enabled using AspNetCore?

谢谢!

推荐答案

由于DI,ASP.NET Core上的配置会有所不同,您可以找到例子.

The configuration on ASP.NET Core will be different due to DI, you can find examples here.

相关部分:

创建新的初始化器.

在 在Startup类的ConfigureServices中调用AddApplicationInsightsTelemetry().例如:

Register it into DI Containers before AddApplicationInsightsTelemetry() is called in the ConfigureServices of your Startup class. For eg:

// Use this if MyCustomTelemetryInitializer can be constructed without DI injected parameters services.AddSingleton<ITelemetryInitializer>(new MyCustomTelemetryInitializer());

OR

// Use this if MyCustomTelemetryInitializer constructor has parameters which are DI injected. services.AddSingleton<ITelemetryInitializer, MyCustomTelemetryInitializer>();

This will ensure the telemetry initializer will be part of the TelemetryConfiguration object.

类似的方法可用于删除所有或特定的TelemetryInitializer.使用以下逻辑 之后后调用 已完成AddApplicationInsightsTelemetry()

Similar approach can be used to remove all or specific TelemetryInitializers. Use the following logic after the call to AddApplicationInsightsTelemetry() is made

public void ConfigureServices(IServiceCollection services) { .. services.AddApplicationInsightsTelemetry("ikey"); // Remove a specific built-in TelemetryInitializer var tiToRemove = services.FirstOrDefault<ServiceDescriptor>(t => t.ImplementationType == typeof(AspNetCoreEnvironmentTelemetryInitializer)); if (tiToRemove != null) { services.Remove(tiToRemove); } // or Remove all services.RemoveAll(typeof(ITelemetryInitializer)); // this requires importing namespace using Microsoft.Extensions.DependencyInjection.Extensions; .. }

更多推荐

ClientIpHeaderTelemetryInitializer和AspNetCore

本文发布于:2023-11-16 10:17:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1603392.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:ClientIpHeaderTelemetryInitializer   AspNetCore

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!