将应用程序见解跟踪日志记录添加到.net核心控制台应用程序

编程入门 行业动态 更新时间:2024-10-26 19:24:56
本文介绍了将应用程序见解跟踪日志记录添加到核心控制台应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个核心控制台应用程序(不是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核心控制台应用程序

本文发布于:2023-11-13 21:50:29,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1585412.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   控制台   见解   核心   日志

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!