mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-14 06:13:35 +01:00
Compare commits
3 Commits
1.6.8
...
stef-1062-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
44be24a129 | ||
|
|
0185b116ca | ||
|
|
237cd227d9 |
@@ -91,3 +91,4 @@ For more details see also [Docker](https://github.com/WireMock-Net/WireMock.Net-
|
||||
|
||||
#### HTTPS / SSL
|
||||
More details on using HTTPS (SSL) can be found here [Wiki : HTTPS](https://github.com/WireMock-Net/WireMock.Net/wiki/Using-HTTPS-(SSL))
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ public sealed class WireMockContainerBuilder : ContainerBuilder<WireMockContaine
|
||||
{ true, new ContainerInfo("sheyenrath/wiremock.net-windows:latest", @"c:\app\__admin\mappings") }
|
||||
};
|
||||
|
||||
private const string DefaultLogger = "WireMockConsoleLogger";
|
||||
private const string DefaultLogger = "WireMockNoNewLinesConsoleLogger";
|
||||
|
||||
private readonly Lazy<Task<bool>> _isWindowsAsLazy = new(async () =>
|
||||
{
|
||||
@@ -157,7 +157,7 @@ public sealed class WireMockContainerBuilder : ContainerBuilder<WireMockContaine
|
||||
return builder
|
||||
.WithPortBinding(WireMockContainer.ContainerPort, true)
|
||||
.WithCommand($"--WireMockLogger {DefaultLogger}")
|
||||
.WithWaitStrategy(waitForContainerOS.UntilMessageIsLogged("By Stef Heyenrath"));
|
||||
.WithWaitStrategy(waitForContainerOS.UntilMessageIsLogged("WireMock.Net server running"));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using Newtonsoft.Json;
|
||||
using WireMock.Admin.Requests;
|
||||
|
||||
namespace WireMock.Logging;
|
||||
@@ -10,58 +10,65 @@ namespace WireMock.Logging;
|
||||
/// <seealso cref="IWireMockLogger" />
|
||||
public class WireMockConsoleLogger : IWireMockLogger
|
||||
{
|
||||
private const string NewlineWindows = "\r\n";
|
||||
private const string NewlineUnix = "\n";
|
||||
|
||||
private readonly bool _removeNewLines;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="WireMockConsoleLogger"/> class.
|
||||
/// </summary>
|
||||
public WireMockConsoleLogger()
|
||||
public WireMockConsoleLogger(bool removeNewLines = false)
|
||||
{
|
||||
_removeNewLines = removeNewLines;
|
||||
|
||||
Console.OutputEncoding = System.Text.Encoding.UTF8;
|
||||
}
|
||||
|
||||
/// <see cref="IWireMockLogger.Debug"/>
|
||||
/// <inheritdoc />
|
||||
public void Debug(string formatString, params object[] args)
|
||||
{
|
||||
Console.WriteLine(Format("Debug", formatString, args));
|
||||
WriteLine(Format("Debug", formatString, args));
|
||||
}
|
||||
|
||||
/// <see cref="IWireMockLogger.Info"/>
|
||||
/// <inheritdoc />
|
||||
public void Info(string formatString, params object[] args)
|
||||
{
|
||||
Console.WriteLine(Format("Info", formatString, args));
|
||||
WriteLine(Format("Info", formatString, args));
|
||||
}
|
||||
|
||||
/// <see cref="IWireMockLogger.Warn"/>
|
||||
/// <inheritdoc />
|
||||
public void Warn(string formatString, params object[] args)
|
||||
{
|
||||
Console.WriteLine(Format("Warn", formatString, args));
|
||||
WriteLine(Format("Warn", formatString, args));
|
||||
}
|
||||
|
||||
/// <see cref="IWireMockLogger.Error(string, object[])"/>
|
||||
/// <inheritdoc />
|
||||
public void Error(string formatString, params object[] args)
|
||||
{
|
||||
Console.WriteLine(Format("Error", formatString, args));
|
||||
WriteLine(Format("Error", formatString, args));
|
||||
}
|
||||
|
||||
/// <see cref="IWireMockLogger.Error(string, Exception)"/>
|
||||
/// <inheritdoc />
|
||||
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;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// <see cref="IWireMockLogger.DebugRequestResponse"/>
|
||||
/// <inheritdoc />
|
||||
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 +77,13 @@ public class WireMockConsoleLogger : IWireMockLogger
|
||||
|
||||
return $"{DateTime.UtcNow} [{level}] : {message}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the specified string value, followed by the current line terminator, to the console.
|
||||
/// </summary>
|
||||
/// <param name="value">The value to write.</param>
|
||||
private void WriteLine(string value)
|
||||
{
|
||||
Console.WriteLine(!_removeNewLines ? value : value.Replace(NewlineWindows, string.Empty).Replace(NewlineUnix, string.Empty));
|
||||
}
|
||||
}
|
||||
@@ -83,10 +83,16 @@ public static class WireMockServerSettingsParser
|
||||
private static void ParseLoggerSettings(WireMockServerSettings settings, IWireMockLogger? logger, SimpleSettingsParser parser)
|
||||
{
|
||||
var loggerType = parser.GetStringValue("WireMockLogger");
|
||||
var removeNewLines = parser.GetBoolValue("RemoveNewLines");
|
||||
|
||||
switch (loggerType)
|
||||
{
|
||||
case nameof(WireMockConsoleLogger):
|
||||
settings.Logger = new WireMockConsoleLogger();
|
||||
settings.Logger = new WireMockConsoleLogger(removeNewLines);
|
||||
break;
|
||||
|
||||
case "WireMockNoNewLinesConsoleLogger":
|
||||
settings.Logger = new WireMockConsoleLogger(true);
|
||||
break;
|
||||
|
||||
case nameof(WireMockNullLogger):
|
||||
|
||||
Reference in New Issue
Block a user