【问题标题】:Configure Layout of Application Logs in Azure Log Stream在 Azure 日志流中配置应用程序日志的布局
【发布时间】:2021-01-22 08:22:17
【问题描述】:

我在 Azure 应用服务中托管了一个 Net Core Web API,我正在尝试以与在我的开发环境中格式化控制台相同的方式格式化 Azure 日志流的输出。

我为此使用 NLog,并使用 NLog ColoredConsole 将所有日志重定向到控制台:

"target": {
      "type": "ColoredConsole",
      "layout": "${var_layout}",
      "rowHighlightingRules": [
        {
          "condition": "level == LogLevel.Trace",
          "foregroundColor": "DarkGray"
        },
        {
          "condition": "level == LogLevel.Debug",
          "foregroundColor": "DarkGray"
        },
        {
          "condition": "level == LogLevel.Warning",
          "foregroundColor": "Yellow"
        },
        {
          "condition": "level == LogLevel.Error",
          "foregroundColor": "Red"
        },
        {
          "condition": "level == LogLevel.Fatal",
          "foregroundColor": "Yellow",
          "backgroundColor": "Red"
        }
      ]
    }

在我的 Startup.cs 中,我删除了 AddConsole() 选项,并将 NLog 配置为将所有格式化的输出发送到 ColoredConsole。

这在我的本地控制台上运行良好,并且所有内容都按预期格式化。

但是,在 Azure 日志流中,我仍然可以看到默认格式(黑底白字)和布局(我使用 NLog 记录的自定义数据丢失)。

我的问题是:为什么 Azure 日志流没有显示格式化的输出?这不是显示控制台正在记录的确切内容吗?

如果没有,如何格式化 Azure 日志流输出?

【问题讨论】:

标签: .net-core azure-web-app-service asp.net-core-webapi nlog


【解决方案1】:

恐怕您的需求在 Azure 上不支持

Log Stream 只是输出控制台消息,而不是真正的控制台,所以颜色会有点棘手。

就像link Rolf Kristensen 的帖子一样,没有关于任何 Azure Log 系统的彩色控制台的解决方案。

【讨论】:

    猜你喜欢
    • 2020-05-24
    • 2022-11-22
    • 2020-06-30
    • 2017-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-13
    • 1970-01-01
    相关资源
    最近更新 更多