Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
200 views
in Technique[技术] by (71.8m points)

.net core - Configure Layout of Application Logs in Azure Log Stream

I have an Net Core Web API hosted in an Azure App Service and I am trying to format the output of the Azure Log Stream in the same way the Console is formatted in my Development environment.

I am using NLog for this and I am redirecting all logs to the Console using the 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"
        }
      ]
    }

In my Startup.cs I removed AddConsole() option and I configured NLog to send all formatted output to the ColoredConsole.

This works well on my local Console and everything is formatted as expected.

However in the Azure Log Stream I can still see the default formatting (all white on black background) and layout (my custom logged data with NLog is missing).

My question is: why the Azure Log Stream is not showing the formatted output? Is that not showing exactly what the Console is logging?

If not, how can I format the Azure Log Stream output?

question from:https://stackoverflow.com/questions/65841572/configure-layout-of-application-logs-in-azure-log-stream

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I'm afraid your need is not supported on Azure.

The Log Stream just output the console message, but not a real console, so it would be a bit tricky with colors.

Just like the link Rolf Kristensen post, there is no solution about colored console with any Azure Log system.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...