0

I am finding explinations like this (and others) reference methods that don't exist.

There is no builder.Logging.AddApplicationInsightsTelemetry() nor is there a builder.Services.AddBlazorApplicationInsights()

What I did try was:

var builder = WebApplication.CreateBuilder(args);
builder.Logging.AddApplicationInsights();

and in appsettings.json I have:

 "ApplicationInsights": {
    "ConnectionString": "InstrumentationKey=***guid***;IngestionEndpoint=https://eastus-8.in.applicationinsights.azure.com/;LiveEndpoint=https://eastus.livediagnostics.monitor.azure.com/"
  },

When I run nothing is written to Application Insights. And my output has the following:

Application Insights Telemetry (unconfigured): {"name":"AppTraces","time":"2023-06-28T22:15:49.4249016Z","tags":{"ai.cloud.roleInstance":"Jasmine","ai.internal.sdkVersion":"il:2.22.0-533"},"data":{"baseType":"MessageData","baseData":{"ver":2,"message":"Now listening on: https://localhost:7229","severityLevel":"Information","properties":{"CategoryName":"Microsoft.Hosting.Lifetime","EventName":"ListeningOnAddress","OriginalFormat":"Now listening on: {address}","address":"https://localhost:7229","EventId":"14"}}}}
Microsoft.Hosting.Lifetime: Information: Now listening on: http://localhost:5068
Application Insights Telemetry (unconfigured): {"name":"AppTraces","time":"2023-06-28T22:15:49.4659785Z","tags":{"ai.cloud.roleInstance":"Jasmine","ai.internal.sdkVersion":"il:2.22.0-533"},"data":{"baseType":"MessageData","baseData":{"ver":2,"message":"Now listening on: http://localhost:5068","severityLevel":"Information","properties":{"CategoryName":"Microsoft.Hosting.Lifetime","EventName":"ListeningOnAddress","OriginalFormat":"Now listening on: {address}","address":"http://localhost:5068","EventId":"14"}}}}
Microsoft.Hosting.Lifetime: Information: Application started. Press Ctrl+C to shut down.
Application Insights Telemetry (unconfigured): {"name":"AppTraces","time":"2023-06-28T22:15:49.4729221Z","tags":{"ai.cloud.roleInstance":"Jasmine","ai.internal.sdkVersion":"il:2.22.0-533"},"data":{"baseType":"MessageData","baseData":{"ver":2,"message":"Application started. Press Ctrl+C to shut down.","severityLevel":"Information","properties":{"CategoryName":"Microsoft.Hosting.Lifetime","OriginalFormat":"Application started. Press Ctrl+C to shut down."}}}}
Microsoft.Hosting.Lifetime: Information: Hosting environment: Development
Application Insights Telemetry (unconfigured): {"name":"AppTraces","time":"2023-06-28T22:15:49.4759303Z","tags":{"ai.cloud.roleInstance":"Jasmine","ai.internal.sdkVersion":"il:2.22.0-533"},"data":{"baseType":"MessageData","baseData":{"ver":2,"message":"Hosting environment: Development","severityLevel":"Information","properties":{"CategoryName":"Microsoft.Hosting.Lifetime","OriginalFormat":"Hosting environment: {EnvName}","EnvName":"Development"}}}}
Microsoft.Hosting.Lifetime: Information: Content root path: C:\git\LouisHowe\LouisHowe.web
Application Insights Telemetry (unconfigured): {"name":"AppTraces","time":"2023-06-28T22:15:49.4789848Z","tags":{"ai.cloud.roleInstance":"Jasmine","ai.internal.sdkVersion":"il:2.22.0-533"},"data":{"baseType":"MessageData","baseData":{"ver":2,"message":"Content root path: C:\\git\\LouisHowe\\LouisHowe.web","severityLevel":"Information","properties":{"CategoryName":"Microsoft.Hosting.Lifetime","OriginalFormat":"Content root path: {ContentRoot}","ContentRoot":"C:\\git\\LouisHowe\\LouisHowe.web"}}}}

Any ideas how I can get this working?

David Thielen
  • 28,723
  • 34
  • 119
  • 193
  • Could you please share your `.csproj` and complete `appsettings.json` file. – Harshitha Jun 29 '23 at 06:19
  • Make sure your `appsettings.json` file is same as shown [here](https://stackoverflow.com/a/73566848/19648279) – Harshitha Jun 29 '23 at 06:20
  • `There is no builder.Logging.AddApplicationInsightsTelemetry() nor is there a builder.Services.AddBlazorApplicationInsights()`. You need to add this piece of code to write the logs to application insights. – – Harshitha Jun 29 '23 at 09:32
  • Please share your Complete `Program.cs` file as well. – Harshitha Jun 29 '23 at 11:50

1 Answers1

0

Turned out to be simple, one more call. In Program.cs add:

builder.Logging.AddApplicationInsights();
builder.Services.AddApplicationInsightsTelemetry();
David Thielen
  • 28,723
  • 34
  • 119
  • 193