使用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);