Baca dalam bahasa Inggris

Bagikan melalui


Pemformatan pencatat konsol default dalam gambar kontainer

Pemformat konsol default yang dikonfigurasi dalam kontainer aspnet telah berubah.

Perilaku sebelumnya

Dalam rilis pelayanan sebelumnya dari .NET 6, gambar kontainer aspnet dikonfigurasi dengan variabel lingkungan Logging__Console__FormatterName yang diatur ke Json. Ini menghasilkan output konsol yang diformat mirip dengan berikut ini:

txt
{"EventId":0,"LogLevel":"Information","Category":"Microsoft.Hosting.Lifetime","Message":"Now listening on: http://localhost:7000/","State":{"Message":"Now listening on: http://localhost:7000/","address":"http://localhost:7000/","{OriginalFormat}":"Now listening on: {address}"}}
{"EventId":0,"LogLevel":"Information","Category":"Microsoft.Hosting.Lifetime","Message":"Now listening on: http://localhost:7001/","State":{"Message":"Now listening on: http://localhost:7001/","address":"http://localhost:7001/","{OriginalFormat}":"Now listening on: {address}"}}
{"EventId":0,"LogLevel":"Information","Category":"Microsoft.Hosting.Lifetime","Message":"Now listening on: http://localhost:7002/","State":{"Message":"Now listening on: http://localhost:7002/","address":"http://localhost:7002/","{OriginalFormat}":"Now listening on: {address}"}}
{"EventId":0,"LogLevel":"Information","Category":"Microsoft.Hosting.Lifetime","Message":"Application started. Press Ctrl\u002BC to shut down.","State":{"Message":"Application started. Press Ctrl\u002BC to shut down.","{OriginalFormat}":"Application started. Press Ctrl\u002BC to shut down."}}
{"EventId":0,"LogLevel":"Information","Category":"Microsoft.Hosting.Lifetime","Message":"Hosting environment: Development","State":{"Message":"Hosting environment: Development","envName":"Development","{OriginalFormat}":"Hosting environment: {envName}"}}
{"EventId":0,"LogLevel":"Information","Category":"Microsoft.Hosting.Lifetime","Message":"Content root path: C:\\source\\temp\\web50","State":{"Message":"Content root path: C:\\source\\temp\\web50","contentRoot":"C:\\source\\temp\\web50","{OriginalFormat}":"Content root path: {contentRoot}"}}

Perilaku yang baru

Mulai dari .NET 6.0.5, aspnet gambar kontainer memiliki Logging__Console__FormatterName variabel lingkungan yang tidak diatur secara default. Ini menghasilkan output konsol yang sederhana, multibaris, dan dapat dibaca manusia mirip dengan berikut ini:

txt
warn: Microsoft.AspNetCore.Server.HttpSys.MessagePump[37]
      Overriding address(es) ''. Binding to endpoints added to UrlPrefixes instead.
info: Microsoft.Hosting.Lifetime[0]
      Now listening on: http://localhost:7000/
info: Microsoft.Hosting.Lifetime[0]
      Now listening on: http://localhost:7001/
info: Microsoft.Hosting.Lifetime[0]
      Now listening on: http://localhost:7002/
info: Microsoft.Hosting.Lifetime[0]
      Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
      Hosting environment: Development
info: Microsoft.Hosting.Lifetime[0]
      Content root path: C:\source\temp\web50

Versi yang diperkenalkan

.NET 6.0.5 (Layanan Mei 2022)

Jenis perubahan yang melanggar

Perubahan ini dapat memengaruhi kompatibilitas sumber.

Alasan untuk berubah

Ketika perubahan untuk menggunakan pemformatan JSON diperkenalkan dalam rilis .NET 6 GA, perubahan merusak banyak skenario yang mengandalkan pemformatan sederhana dan asli seperti yang dijelaskan dalam dotnet/dotnet-docker#2725.

Jika Anda ingin terus menggunakan pemformatan JSON, Anda dapat mengonfigurasi kontainer Anda untuk menggunakannya dengan mengatur nilai variabel lingkungan Logging__Console__FormatterName ke Json.

API yang Terpengaruh

Tidak ada.

Lihat juga