使用Application Insights在Azure上进行ASP.NET Core跟踪日志记录 [英] ASP.NET Core trace logging on Azure with Application Insights

查看:77
本文介绍了使用Application Insights在Azure上进行ASP.NET Core跟踪日志记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个配置了Application Insights的ASP.NET Core Web项目部署到Azure.洞察力可以很好地处理请求等数据,但无法显示日志.

I have an ASP.NET Core web project deployed to Azure with Application Insights configured. Insights is receiving data fine for requests etc. but I am unable to get it to display my logs.

我正在使用普通的Microsoft.Extensions.Logging框架,并且在控制器操作上记录的测试错误为

I am using the vanilla Microsoft.Extensions.Logging framework and have a test error being logged on a controller action as

logger.LogError("Test application insights message");

在我设置的Startup.cs配置方法中

In my Startup.cs Configure method I have set

loggerFactory.AddAzureWebAppDiagnostics();

...,并且可以成功看到错误消息出现在Azure日志流中:

... and can successfully see the error message appear in Azure logs streaming:

2017-04-14 11:06:00.313 +00:00 [Error] Test application insights message

但是,我也希望此消息出现在Application Insights跟踪中,但找不到它.我想我需要配置ILoggerFactory,但不确定如何以及找不到关于该主题的任何文档.

However, I also want this message to appear in Application Insights trace but it is nowhere to be found. I think I need to configure the ILoggerFactory but not sure how and can't find any docs on the subject.

预先感谢您的帮助

推荐答案

用其他任何人试图解决此问题,我得到了想要的结果,如下所示:

case anybody else trying to resolve this, I got the results I wanted with the following:

loggerFactory.AddApplicationInsights(app.ApplicationServices);

这篇关于使用Application Insights在Azure上进行ASP.NET Core跟踪日志记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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