'How to access AppInsights TelemetryClient inside of a global action filter?
I'm trying to log some data to Azure with TelemetryClient inside my global action filter. The TelemetryClient is passed through the constructor, but environment variables are showing as null inside the TelemetryClient.
I have it defined in Startup.CS:
// setting up env variables
services.addApplicationInsightsTelemetry();
var env = new EnvironmentInitializer();
env.EnvironmentName = "foo";
env.ServiceOffering = "bar";
env.ServiceLine = "yuh";
......
TelemetryConfiguration _telemetryConfiguration = TelemetryConfiguration.CreateDefault();
_telemetryConfiguration.TelemetryInitializer.Add((env));
services.AddSingleton<TelemetryConfiguration>(_telemetryConfiguration);
services.AddSingleton<ITelemetryInitializer>(env);
Inside my custom filter constructor:
public class SomeGlobalFilter : ActionFilterAttribute
{
private readonly TelemetryClient telemetry;
public SomeGlobalFilter(TelemetryClient telemetry) {
this.telemetry = telemetry;
}
}
I've tried:
private TelemetryClient telemetry;
private readonly TelemetryConfiguration;
public SomeGlobalFilter(TelemetryConfiguration config) {
this.telemetry = new TelemetryClient(config);
}
But config has null environment values. I'm just learning .NET so I'm probably missing a step, but I couldn't figure it out from the docs.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
