I have one asp.net core 3.1 console app which basically is a background jobs. I am able to log to the application insight. But there is one persistent log which is logging every 15 minutes which is.
AI: TelemetryChannel found a telemetry item without an InstrumentationKey. This is a required field and must be set in either your config file or at application startup.
I have gone through other SO answer and tried the recommended solution but still is am seeing this log. Some of the post I looked on are How to find the source of "TelemetryChannel found a telemetry item without an InstrumentationKey"
Using nlog with ApplicationInsightsTelemetryWorkerService in .net core 3.1 console app
Based on this recommendation I tried with below code.
services.AddApplicationInsightsTelemetryWorkerService(
options =>
Configuration
.GetSection("ApplicationInsights")
.Bind(options)
);
NLog.LogManager.Configuration.FindTargetByName<ApplicationInsightsTarget>("ai").InstrumentationKey
= Configuration["ApplicationInsights:InstrumentationKey"].ToString();
And my app settings has config like below.
"ApplicationInsights": {
"InstrumentationKey": "instrumentation-key",
"DeveloperMode": false,
"EnableRequestTrackingTelemetryModule": true,
"EnableAdaptiveSampling": false,
"EnableActiveTelemetryConfigurationSetup": true
},
And package that i am using are
<PackageReference Include="Microsoft.ApplicationInsights.NLogTarget" Version="2.14.0" />
<PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.15.0" />
Did anyone get luck fixing this issue?
CodePudding user response:
- Try to copy the
appsettings.json
to the application root folder during publishing. - Check by adding an application insight resource id to to the csproj:
<ApplicationInsightsResourceId>/subscriptions/abc</ApplicationInsightsResourceId>
CodePudding user response:
Looks like this is the existing issue on the package version in 2.15.0 and above.
Microsoft.ApplicationInsights.WorkerService
I reverted the version back to 2.14.0. That fixed the issue for now.