简体   繁体   English

我可以在Asp.net Web.API中的AppStart一次自定义RequestTelemetry属性吗?

[英]Can I customize RequestTelemetry properties once at AppStart in Asp.net Web.API

I want to add a property say version information to RequestTelemetry of (HttpRequest). 我想向(HttpRequest)的RequestTelemetry添加一个属性,例如版本信息。 This link provides an approach - by overriding ITelemetryInitializer Initialize method. 链接提供了一种方法-通过重写ITelemetryInitializer的Initialize方法。 However, it is getting executed every time when a request hits the server. 但是,它每次在请求到达服务器时都会执行。 I want to set it once at App Start as my property( eg., assembly ver/Proj version) does not change often. 我想在应用启动时设置一次,因为我的属性(例如,程序集版本/ Proj版本)不经常更改。

我不确定您可以执行此操作,因为每个请求都会获得一个RequestTelemetry的新实例。

This is not possible. 这是不可能的。 TelemetryInitializer override, is a way to collect telemetry in a custom fashion and is called with every request. TelemetryInitializer覆盖是一种以自定义方式收集遥测的方式,并且在每个请求中都会调用它。

I got to know of a way to do this through context initializers but it is not recommended - http://apmtips.com/blog/2015/06/09/do-not-use-context-initializers/ 我知道一种通过上下文初始化器执行此操作的方法,但不建议这样做-http://apmtips.com/blog/2015/06/09/do-not-use-context-initializers/

Instead he asked to use ITelemetryInitializers with a static value so that it is not calculated for every request. 相反,他要求使用带有静态值的ITelemetryInitializers,以便不会为每个请求都计算出它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ASP.NET Core Web.API中的拦截调用者语言 - Intercept caller language in ASP.NET Core Web.API 带有WEB.API和Castle Windsor容器的ASP.NET MVC - ASP.NET MVC with WEB.API and Castle Windsor container 使用 asp.net web.api json 不起作用 - Consuming asp.net web.api json not working 如何在ASP.NET Web.Api中运行后台任务? - How do I run Background Tasks in ASP.NET Web.Api? 使用Asp.net MVC web.api为什么要重定向而不是只调用其他函数? - Using Asp.net MVC web.api why should I redirect rather than just call other functions? WEB API + ASP.NET尝试以json格式显示来自WEB.API的数据 - WEB API + ASP.NET trying to display data from WEB.API in json format 我在哪里可以找到或添加 ASP.NET 项目中的 _AppStart 和 _PageStart? - Where can I find or add the _AppStart & _PageStart in ASP.NET projects? ASP.NET Core 2.1 Web.API更改应用程序见解的日志记录检测键 - ASP.NET Core 2.1 Web.API change application insights instrumentation key for logging ASP.NET web.api帮助页面不显示任何描述 - ASP.NET web.api Help Page does not show any description 如何在AuthorAttribute的ASP.NET Web.API MVC 5的IsAuthorized上获取Post参数 - How to get Post parameters on IsAuthorized of AuthorizeAttribute ASP.NET Web.API MVC 5
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM