Mise en forme de l’enregistreur d’événements de console par défaut dans les images conteneur

Le formateur de console par défaut configuré dans les conteneurs aspnet a changé.

Comportement précédent

Dans les versions de maintenance précédentes de .NET 6, les images conteneur aspnet étaient configurées avec la variable d’environnement Logging__Console__FormatterName définie sur Json. La sortie de console était alors mise en forme de la façon suivante :

{"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}"}}

Nouveau comportement

À compter de .NET 6.0.5, les images conteneur aspnet ont la variable d’environnement Logging__Console__FormatterName non définie par défaut. La sortie de console obtenue est simple, multiligne et lisible par l’utilisateur, comme l’exemple suivant :

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

Version introduite

.NET 6.0.5 (maintenance de mai 2022)

Type de changement cassant

Ce changement peut affecter la compatibilité source.

Raison du changement

Quand l’utilisation de la mise en forme JSON a été introduite dans la version .NET 6 GA, elle a cassé de nombreux scénarios qui s’appuyaient sur la mise en forme simple d’origine, comme décrit dans dotnet/dotnet-docker#2725.

Si vous voulez continuer à utiliser la mise en forme JSON, vous pouvez configurer votre conteneur pour l’utiliser en définissant la valeur de la variable d’environnement Logging__Console__FormatterName sur Json.

API affectées

Aucun.

Voir aussi