我剛剛將我的 asp web api 專案從 net5 升級到 net6,而沒有觸及任何一段代碼。一切正常,但我注意到在容器內運行時,日志輸出顯示為一系列 Json 物件,而不是預期的控制臺格式。
前
info: Microsoft.Hosting.Lifetime[14]
Now listening on: https://localhost:5001
info: Microsoft.Hosting.Lifetime[14]
Now listening on: http://localhost:5000
后
{"EventId":14,"LogLevel":"Information","Category":"Microsoft.Hosting.Lifetime","Message":"Now listening on: https://[::]:5001","State":{"Message":"Now listening on: https://[::]:5001","address":"https://[::]:5001","{OriginalFormat}":"Now listening on: {address}"}}
{"EventId":14,"LogLevel":"Information","Category":"Microsoft.Hosting.Lifetime","Message":"Now listening on: http://[::]:5000","State":{"Message":"Now listening on: http://[::]:5000","address":"http://[::]:5000","{OriginalFormat}":"Now listening on: {address}"}}
我不知道問題是來自發送到 std 的實際日志結構的修改還是來自容器引擎(在我的情況下為 docker)。
它在容器外的控制臺中作業正常。
有任何想法嗎 ?
uj5u.com熱心網友回復:
顯然,控制臺日志記錄的默認格式已從“簡單”更改為“Json”。
您可以通過將此行添加到您的 Dockerfile(如果您進行多階段構建,它會出現在最終映像中的某個位置)將其更改回來:
ENV Logging__Console__FormatterName=Simple
您不能在 appsettings.json 檔案中更改它,因為 Microsoft 在其 Docker 映像中設定了環境變數,這將覆寫您的組態檔中的任何設定。您必須設定環境變數。
此處的更改有一個未解決的問題:https : //github.com/dotnet/dotnet-docker/issues/3274
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/365516.html
上一篇:System.Diagnostics.TraceSource不向ApplicationInsights發送資料
下一篇:如何在AlpineLinuxDockerContainer中安裝“MicrosoftAccessDriver(*.mdb,*.accdb)”驅動程式
