英文:
In Blazor how do I get Logger talking to ApplicationInsights
问题
我发现像这样(和其他一些)的解释引用了不存在的方法。
没有builder.Logging.AddApplicationInsightsTelemetry()
,也没有builder.Services.AddBlazorApplicationInsights()
我尝试过以下方法:
var builder = WebApplication.CreateBuilder(args);
builder.Logging.AddApplicationInsights();
而且在appsettings.json中我有:
"ApplicationInsights": {
"ConnectionString": "InstrumentationKey=***guid***;IngestionEndpoint=https://eastus-8.in.applicationinsights.azure.com/;LiveEndpoint=https://eastus.livediagnostics.monitor.azure.com/"
},
当我运行时,没有任何数据被写入到Application Insights。而且我的输出如下:
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"}}}}
有没有什么办法可以让这个工作起来?
英文:
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?
答案1
得分: 0
在Program.cs中添加以下内容:
builder.Logging.AddApplicationInsights();
builder.Services.AddApplicationInsightsTelemetry();
英文:
Turned out to be simple, one more call. In Program.cs add:
builder.Logging.AddApplicationInsights();
builder.Services.AddApplicationInsightsTelemetry();
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论