From 32532078d6cdb1933fc55986a292f27be5645f43 Mon Sep 17 00:00:00 2001 From: "Chris Ross (ASP.NET)" Date: Mon, 22 Oct 2018 14:51:29 -0700 Subject: [PATCH] Log binary data as a parameter #2860 --- samples/SampleApp/Startup.cs | 1 + src/Kestrel.Core/Adapter/Internal/LoggingStream.cs | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/samples/SampleApp/Startup.cs b/samples/SampleApp/Startup.cs index ad38e3920d..32890238ef 100644 --- a/samples/SampleApp/Startup.cs +++ b/samples/SampleApp/Startup.cs @@ -66,6 +66,7 @@ namespace SampleApp var hostBuilder = new WebHostBuilder() .ConfigureLogging((_, factory) => { + factory.SetMinimumLevel(LogLevel.Debug); factory.AddConsole(); }) .ConfigureAppConfiguration((hostingContext, config) => diff --git a/src/Kestrel.Core/Adapter/Internal/LoggingStream.cs b/src/Kestrel.Core/Adapter/Internal/LoggingStream.cs index e591d4acf4..42722f2413 100644 --- a/src/Kestrel.Core/Adapter/Internal/LoggingStream.cs +++ b/src/Kestrel.Core/Adapter/Internal/LoggingStream.cs @@ -174,13 +174,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal builder.Append(" "); } builder.AppendLine(); + builder.Append("{0}"); + + var rawDataBuilder = new StringBuilder(); // Write the bytes as if they were ASCII for (int i = 0; i < buffer.Length; i++) { - builder.Append((char)buffer[i]); + rawDataBuilder.Append((char)buffer[i]); } - _logger.LogDebug(builder.ToString()); + _logger.LogDebug(builder.ToString(), rawDataBuilder.ToString()); } // The below APM methods call the underlying Read/WriteAsync methods which will still be logged.