繁体   English   中英

如何将自定义消息记录到 azure 门户分析监控日志

[英]how to log custom messages to azure portal analytics monitoring logs

我正在尝试在我的 c# asp dot net core web api 中添加自定义日志。 我能够在 Azure 门户 -> 应用程序洞察 -> 日志中找到 api 调用日志。

但我无法找到我使用以下代码输入的自定义日志。 什么地方可以搜索它们。

public async Task Invoke(HttpContext httpContext)
{
    // First, get the incoming request
    var request = await FormatRequest(httpContext.Request);

    // TODO: Save log to chosen datastore
    _logger.LogInformation('custommessage101');

    // ------
}

在日志分析查询编辑器中,我使用了下面的查询,但它没有获取任何内容。 它甚至是我正在查看的正确位置(Azure 门户 -> 应用程序洞察 -> 日志)吗?

requests | search "custommessage101"

可能是当您配置记录器时,您将日志级别设置为高于信息。

以下设置日志级别,以便存储信息日志记录:

builder.AddFilter<Microsoft.Extensions.Logging.ApplicationInsights.ApplicationInsightsLoggerProvider>("", LogLevel.Information);

记录到ILogger界面的消息最终会作为应用程序洞察中的痕迹。 一个示例查询是:

traces | where message == "custommessage101"

另一种选择是搜索

在此处输入图片说明

应用程序洞察消息的默认日志级别设置为Warning 正如设拉子所指出的,您需要将其设置为信息性。 您可以使用 Shiraz 所示的代码或通过调整 appsettings.json 文件来做到这一点:

{
  "Logging": {
    "LogLevel": {
      "Default": "Information"
    },
    "ApplicationInsights": {
      "LogLevel": {
        "Default": "Information"
      }
    }
  }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM