本文介绍了将应用洞察跟踪日志记录添加到 .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"类型的服务.

大概是因为这不是 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-申请.

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

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

09-01 20:02