diff --git a/src/WireMock.Net.Testcontainers/WireMockContainerBuilder.cs b/src/WireMock.Net.Testcontainers/WireMockContainerBuilder.cs index fbbb9f0f..ca4ac6ea 100644 --- a/src/WireMock.Net.Testcontainers/WireMockContainerBuilder.cs +++ b/src/WireMock.Net.Testcontainers/WireMockContainerBuilder.cs @@ -21,7 +21,7 @@ public sealed class WireMockContainerBuilder : ContainerBuilder> _isWindowsAsLazy = new(async () => { diff --git a/src/WireMock.Net/Logging/WireMockConsoleLogger.cs b/src/WireMock.Net/Logging/WireMockConsoleLogger.cs index f798c435..afd492ac 100644 --- a/src/WireMock.Net/Logging/WireMockConsoleLogger.cs +++ b/src/WireMock.Net/Logging/WireMockConsoleLogger.cs @@ -1,5 +1,5 @@ -using Newtonsoft.Json; using System; +using Newtonsoft.Json; using WireMock.Admin.Requests; namespace WireMock.Logging; @@ -10,58 +10,62 @@ namespace WireMock.Logging; /// public class WireMockConsoleLogger : IWireMockLogger { + private readonly bool _removeNewLines; + /// /// Initializes a new instance of the class. /// - public WireMockConsoleLogger() + public WireMockConsoleLogger(bool removeNewLines = false) { + _removeNewLines = removeNewLines; + Console.OutputEncoding = System.Text.Encoding.UTF8; } - /// + /// public void Debug(string formatString, params object[] args) { - Console.WriteLine(Format("Debug", formatString, args)); + WriteLine(Format("Debug", formatString, args)); } - /// + /// public void Info(string formatString, params object[] args) { - Console.WriteLine(Format("Info", formatString, args)); + WriteLine(Format("Info", formatString, args)); } - /// + /// public void Warn(string formatString, params object[] args) { - Console.WriteLine(Format("Warn", formatString, args)); + WriteLine(Format("Warn", formatString, args)); } - /// + /// public void Error(string formatString, params object[] args) { - Console.WriteLine(Format("Error", formatString, args)); + WriteLine(Format("Error", formatString, args)); } - /// + /// public void Error(string formatString, Exception exception) { - Console.WriteLine(Format("Error", formatString, exception.Message)); + WriteLine(Format("Error", formatString, exception.Message)); if (exception is AggregateException ae) { ae.Handle(ex => { - Console.WriteLine(Format("Error", "Exception {0}", ex.Message)); + WriteLine(Format("Error", "Exception {0}", ex.Message)); return true; }); } } - /// + /// public void DebugRequestResponse(LogEntryModel logEntryModel, bool isAdminRequest) { string message = JsonConvert.SerializeObject(logEntryModel, Formatting.Indented); - Console.WriteLine(Format("DebugRequestResponse", "Admin[{0}] {1}", isAdminRequest, message)); + WriteLine(Format("DebugRequestResponse", "Admin[{0}] {1}", isAdminRequest, message)); } private static string Format(string level, string formatString, params object[] args) @@ -70,4 +74,13 @@ public class WireMockConsoleLogger : IWireMockLogger return $"{DateTime.UtcNow} [{level}] : {message}"; } + + /// + /// Writes the specified string value, followed by the current line terminator, to the console. + /// + /// The value to write. + private void WriteLine(string value) + { + Console.WriteLine(!_removeNewLines ? value : value.Replace(Environment.NewLine, string.Empty)); + } } \ No newline at end of file diff --git a/src/WireMock.Net/Settings/WireMockServerSettingsParser.cs b/src/WireMock.Net/Settings/WireMockServerSettingsParser.cs index 20c18d5f..4f4f598f 100644 --- a/src/WireMock.Net/Settings/WireMockServerSettingsParser.cs +++ b/src/WireMock.Net/Settings/WireMockServerSettingsParser.cs @@ -83,10 +83,16 @@ public static class WireMockServerSettingsParser private static void ParseLoggerSettings(WireMockServerSettings settings, IWireMockLogger? logger, SimpleSettingsParser parser) { var loggerType = parser.GetStringValue("WireMockLogger"); + var replaceNewLines = parser.GetBoolValue("ReplaceNewLines"); + switch (loggerType) { case nameof(WireMockConsoleLogger): - settings.Logger = new WireMockConsoleLogger(); + settings.Logger = new WireMockConsoleLogger(replaceNewLines); + break; + + case "WireMockNoNewLinesConsoleLogger": + settings.Logger = new WireMockConsoleLogger(true); break; case nameof(WireMockNullLogger):