【问题标题】:Trouble Configuring Tracing Application Insights in ASP.NET Core 2.0 Razor Pages在 ASP.NET Core 2.0 Razor 页面中配置跟踪 Application Insights 时遇到问题
【发布时间】:2018-04-23 17:53:55
【问题描述】:

我在 Visual Studio 2017 中创建了一个新的 ASP.NET Core 2.0 Web 应用程序,从而实现了 Razor Pages。

在我的 Index.cshtml.cs 文件中,我实现了这个:

    public void OnGet()
    {
        Trace.TraceError("*************** INDEX ERROR ***************");
        Trace.TraceWarning("*************** INDEX WARNING ***************");
        Trace.TraceInformation("*************** INDEX INFORMATION ***************");
        Trace.WriteLine("*************** INDEX WRITELINE ***************");

        var telemetry = new Microsoft.ApplicationInsights.TelemetryClient();
        telemetry.TrackTrace("*************** INDEX TRACKTRACE ***************");
    }

我对我的 Application Insights 实例进行了所有配置。

appsettings.json

“记录”:{ “包含范围”:错误, “日志级别”:{ “默认”:“跟踪” } },

appsettings.Development.json

“记录”:{ “包含范围”:错误, “日志级别”:{ “默认”:“跟踪”, “系统”:“信息”, “微软”:“信息” } }

当我运行我的页面并查看日志流页面时,我可以看到 telemetry.TrackTrace 条目,但看不到 Trace.Trace* 条目。

我错过了什么?

【问题讨论】:

    标签: asp.net-core-2.0 azure-application-insights


    【解决方案1】:

    如果您使用 Application Insights SDK for Asp.Net Core,它只能收集使用ILogger 机制发送的跟踪。如果您前往此路线,请按照此处的说明进行操作: https://github.com/Microsoft/ApplicationInsights-aspnetcore/wiki/Logging

    但您似乎正在使用 System.Diagnostics.Trace 方法进行日志记录。 Application Insights 可以捕获这些,但它需要安装额外的 nuget (https://www.nuget.org/packages/Microsoft.ApplicationInsights.TraceListener/2.6.0-beta3),它的最新测试版支持 .net 核心应用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-06-28
      • 1970-01-01
      • 1970-01-01
      • 2018-12-24
      • 1970-01-01
      • 2018-11-24
      • 2020-12-10
      相关资源
      最近更新 更多