将应用程序见解跟踪日志记录添加到.net核心控制台应用程序 [英] add app insights trace logging to .net core console application

查看:82
本文介绍了将应用程序见解跟踪日志记录添加到.net核心控制台应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个.net核心控制台应用程序(不是AspNetCore),我想添加应用程序见解日志记录,以将跟踪日志推送到应用程序见解。我曾尝试使用Microsoft.ApplicationInsights.AspNetCore,但是当我这样做时:

I've got a .net 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.

是有没有办法可以将跟踪日志记录从.net核心控制台应用程序中推送到App Insights?

Is there a way I can get trace logging pushed to App Insights from within my .net core console app?

推荐答案

使用Microsoft.ApplicationInsights如 https:中所述: //github.com/Microsoft/ApplicationInsights-aspnetcore/wiki/Getting-Started-for-a.NET-Core-console-application

Use Microsoft.ApplicationInsights as described in https://github.com/Microsoft/ApplicationInsights-aspnetcore/wiki/Getting-Started-for-a-.NET-Core-console-application.

这篇关于将应用程序见解跟踪日志记录添加到.net核心控制台应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆