mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-02-23 01:04:55 +01:00
Compare commits
3 Commits
ws2
...
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
|
#### 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))
|
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") }
|
{ 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 () =>
|
private readonly Lazy<Task<bool>> _isWindowsAsLazy = new(async () =>
|
||||||
{
|
{
|
||||||
@@ -157,7 +157,7 @@ public sealed class WireMockContainerBuilder : ContainerBuilder<WireMockContaine
|
|||||||
return builder
|
return builder
|
||||||
.WithPortBinding(WireMockContainer.ContainerPort, true)
|
.WithPortBinding(WireMockContainer.ContainerPort, true)
|
||||||
.WithCommand($"--WireMockLogger {DefaultLogger}")
|
.WithCommand($"--WireMockLogger {DefaultLogger}")
|
||||||
.WithWaitStrategy(waitForContainerOS.UntilMessageIsLogged("By Stef Heyenrath"));
|
.WithWaitStrategy(waitForContainerOS.UntilMessageIsLogged("WireMock.Net server running"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
using Newtonsoft.Json;
|
|
||||||
using System;
|
using System;
|
||||||
|
using Newtonsoft.Json;
|
||||||
using WireMock.Admin.Requests;
|
using WireMock.Admin.Requests;
|
||||||
|
|
||||||
namespace WireMock.Logging;
|
namespace WireMock.Logging;
|
||||||
@@ -10,58 +10,65 @@ namespace WireMock.Logging;
|
|||||||
/// <seealso cref="IWireMockLogger" />
|
/// <seealso cref="IWireMockLogger" />
|
||||||
public class WireMockConsoleLogger : IWireMockLogger
|
public class WireMockConsoleLogger : IWireMockLogger
|
||||||
{
|
{
|
||||||
|
private const string NewlineWindows = "\r\n";
|
||||||
|
private const string NewlineUnix = "\n";
|
||||||
|
|
||||||
|
private readonly bool _removeNewLines;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="WireMockConsoleLogger"/> class.
|
/// Initializes a new instance of the <see cref="WireMockConsoleLogger"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public WireMockConsoleLogger()
|
public WireMockConsoleLogger(bool removeNewLines = false)
|
||||||
{
|
{
|
||||||
|
_removeNewLines = removeNewLines;
|
||||||
|
|
||||||
Console.OutputEncoding = System.Text.Encoding.UTF8;
|
Console.OutputEncoding = System.Text.Encoding.UTF8;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <see cref="IWireMockLogger.Debug"/>
|
/// <inheritdoc />
|
||||||
public void Debug(string formatString, params object[] args)
|
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)
|
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)
|
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)
|
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)
|
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)
|
if (exception is AggregateException ae)
|
||||||
{
|
{
|
||||||
ae.Handle(ex =>
|
ae.Handle(ex =>
|
||||||
{
|
{
|
||||||
Console.WriteLine(Format("Error", "Exception {0}", ex.Message));
|
WriteLine(Format("Error", "Exception {0}", ex.Message));
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <see cref="IWireMockLogger.DebugRequestResponse"/>
|
/// <inheritdoc />
|
||||||
public void DebugRequestResponse(LogEntryModel logEntryModel, bool isAdminRequest)
|
public void DebugRequestResponse(LogEntryModel logEntryModel, bool isAdminRequest)
|
||||||
{
|
{
|
||||||
string message = JsonConvert.SerializeObject(logEntryModel, Formatting.Indented);
|
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)
|
private static string Format(string level, string formatString, params object[] args)
|
||||||
@@ -70,4 +77,13 @@ public class WireMockConsoleLogger : IWireMockLogger
|
|||||||
|
|
||||||
return $"{DateTime.UtcNow} [{level}] : {message}";
|
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)
|
private static void ParseLoggerSettings(WireMockServerSettings settings, IWireMockLogger? logger, SimpleSettingsParser parser)
|
||||||
{
|
{
|
||||||
var loggerType = parser.GetStringValue("WireMockLogger");
|
var loggerType = parser.GetStringValue("WireMockLogger");
|
||||||
|
var removeNewLines = parser.GetBoolValue("RemoveNewLines");
|
||||||
|
|
||||||
switch (loggerType)
|
switch (loggerType)
|
||||||
{
|
{
|
||||||
case nameof(WireMockConsoleLogger):
|
case nameof(WireMockConsoleLogger):
|
||||||
settings.Logger = new WireMockConsoleLogger();
|
settings.Logger = new WireMockConsoleLogger(removeNewLines);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "WireMockNoNewLinesConsoleLogger":
|
||||||
|
settings.Logger = new WireMockConsoleLogger(true);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case nameof(WireMockNullLogger):
|
case nameof(WireMockNullLogger):
|
||||||
|
|||||||
Reference in New Issue
Block a user