不使用ASP.Net Core 2.0应用程序将遥测信息记录到调试窗口

时间:2017-10-09 19:21:44

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

我正在Visual Studio 2017中编写ASP.NET Core 2.0应用程序。我已经登录控制器,如下所示:

    public HomeController(ILogger<HomeController> logger)
    {
        this._logger = logger;
    }

    public IActionResult Index()
    {
        _logger.LogInformation("In The Index");
        return View();
    }

这会在调试窗口中生成日志:

  

WebApplication4.Controllers.HomeController:信息:在索引中

但是,我想记录所有这些遥测方法:

  

应用程序洞察遥测(未配置):{&#34; name&#34;:&#34; Microsoft.ApplicationInsights.Dev.Message&#34;,&#34; time&#34;:&#34; 2017- 10-09T19:11:31.1311753Z&#34;&#34;标记&#34; {&#34; ai.internal.nodeName&#34;:&#34; DESKTOP-MBRK754&#34;&#34; ai.operation.id&#34;:&#34; 7a80811a-422cb8019de22af6&#34;&#34; ai.location.ip&#34;:&#34; 127.0.0.1&#34;&#34; AI .cloud.roleInstance&#34;:&#34; DESKTOP-MBRK754&#34;&#34; ai.operation.parentId&#34;:&#34; | 7a80811a-422cb8019de22af6&#34;&#34;。 ai.application.ver&#34;:&#34; 1.0.0.0&#34;,&#34; ai.operation.name&#34;:&#34; GET Home / Index&#34;,&#34; ai.internal.sdkVersion&#34;:&#34; aspnet5c:2.1.1&#34;}&#34;数据&#34; {&#34;碱基类型&#34;:&#34; MessageData&#34; ,&#34; baseData&#34;:{&#34; ver&#34;:2,&#34; message&#34;:&#34;使用参数执行操作方法WebApplication4.Controllers.HomeController.Index(WebApplication4) ((null)) - ModelState是有效的&#34;,&#34; severityLevel&#34;:&#34;信息&#34;,&#34;属性&#34;:{&#34; AspNetCoreEnvironment&#34;: &#3 4;开发&#34;,&#34; ValidationState&#34;:&#34;有效&#34;,&#34; ActionName&#34;:&#34; WebApplication4.Controllers.HomeController.Index(WebApplication4)&# 34;,&#34;类别名称&#34;:&#34; Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker&#34;&#34; DeveloperMode&#34;:&#34;真&#34;&#34 ; {OriginalFormat}&#34;:&#34;使用参数执行操作方法{ActionName}({Arguments}) - ModelState为{ValidationState}&#34;}}}}

我的appsettings.json看起来像这样:

"Logging": {
  "IncludeScopes": false,
  "LogLevel": {
    "Default": "Information"
  }
}

如何过滤掉只是遥测信息?

1 个答案:

答案 0 :(得分:1)

Startup.Configure()中添加以下行Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration.Active.DisableTelemetry = true;

Sources