我有一个核心控制台应用程序(不是AspNetCore),我想添加应用程序见解日志记录,以将跟踪日志推送到应用程序见解。我曾尝试使用Microsoft.ApplicationInsights.AspNetCore,但是当我这样做时:
I've got a core console application (not AspNetCore), and I want to add app insights logging that will push out the trace logs to app insights. I have tried using Microsoft.ApplicationInsights.AspNetCore, but when I do:
factory.AddApplicationInsights(serviceProvider);它抛出一个错误,表示找不到托管环境
it throws an error saying it can't find the hosting environment
在尝试激活 Microsoft.ApplicationInsights.AspNetCore.TelemetryInitializers.AspNetCoreEnvironmentTelemetryInitializer时无法解析类型为 Microsoft.AspNetCore.Hosting.IHostingEnvironment的服务。
Unable to resolve service for type 'Microsoft.AspNetCore.Hosting.IHostingEnvironment' while attempting to activate 'Microsoft.ApplicationInsights.AspNetCore.TelemetryInitializers.AspNetCoreEnvironmentTelemetryInitializer'.
大概是因为这不是一个AspNetCore应用程序,而仅仅是一个纯控制台应用程序。
presumably because this is not an AspNetCore app, but just a pure console app.
是有没有办法可以将跟踪日志记录从核心控制台应用程序中推送到App Insights?
Is there a way I can get trace logging pushed to App Insights from within my core console app?
推荐答案使用Microsoft.ApplicationInsights如 https:中所述: //github/Microsoft/ApplicationInsights-aspnetcore/wiki/Getting-Started-for-a.NET-Core-console-application 。
Use Microsoft.ApplicationInsights as described in github/Microsoft/ApplicationInsights-aspnetcore/wiki/Getting-Started-for-a-.NET-Core-console-application.
更多推荐
将应用程序见解跟踪日志记录添加到.net核心控制台应用程序
发布评论