Create dotnet-wiremock tool (#542)

* dotnet tool

* .

* c

* x

* ### As a dotnet tool

* help

* v
This commit is contained in:
Stef Heyenrath
2020-11-25 14:36:01 +00:00
committed by GitHub
parent 4fb455a1b1
commit 45713eb0d9
16 changed files with 343 additions and 127 deletions

View File

@@ -0,0 +1,61 @@
using System;
using System.Text.Json;
using Microsoft.Extensions.Logging;
using WireMock.Admin.Requests;
using WireMock.Logging;
namespace WireMock
{
public class WireMockLogger : IWireMockLogger
{
private readonly JsonSerializerOptions options = new JsonSerializerOptions
{
WriteIndented = true
};
private readonly ILogger _logger;
public WireMockLogger(ILogger logger)
{
_logger = logger;
}
/// <see cref="IWireMockLogger.Debug"/>
public void Debug(string formatString, params object[] args)
{
_logger.LogDebug(formatString, args);
}
/// <see cref="IWireMockLogger.Info"/>
public void Info(string formatString, params object[] args)
{
_logger.LogInformation(formatString, args);
}
/// <see cref="IWireMockLogger.Warn"/>
public void Warn(string formatString, params object[] args)
{
_logger.LogWarning(formatString, args);
}
/// <see cref="IWireMockLogger.Error(string, object[])"/>
public void Error(string formatString, params object[] args)
{
_logger.LogError(formatString, args);
}
/// <see cref="IWireMockLogger.Error(string, Exception)"/>
public void Error(string formatString, Exception exception)
{
_logger.LogError(formatString, exception);
}
/// <see cref="IWireMockLogger.DebugRequestResponse"/>
public void DebugRequestResponse(LogEntryModel logEntryModel, bool isAdminRequest)
{
string message = JsonSerializer.Serialize(logEntryModel, options);
_logger.LogDebug("Admin[{IsAdmin}] {Message}", isAdminRequest, message);
}
}
}