[英]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.