mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-03-26 19:31:48 +01:00
Log Exception (#405)
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
using log4net;
|
using System;
|
||||||
|
using log4net;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Wiremock.Net.Service;
|
using Wiremock.Net.Service;
|
||||||
using WireMock.Admin.Requests;
|
using WireMock.Admin.Requests;
|
||||||
@@ -30,6 +31,11 @@ namespace WireMock.Net.Service
|
|||||||
Log.ErrorFormat(formatString, args);
|
Log.ErrorFormat(formatString, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Error(string message, Exception exception)
|
||||||
|
{
|
||||||
|
Log.Error(message, exception);
|
||||||
|
}
|
||||||
|
|
||||||
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);
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
using log4net;
|
using System;
|
||||||
|
using log4net;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using WireMock.Logging;
|
using WireMock.Logging;
|
||||||
using WireMock.Models.Requests;
|
|
||||||
|
|
||||||
namespace WireMock.Net.StandAlone.NETCoreApp
|
namespace WireMock.Net.StandAlone.NETCoreApp
|
||||||
{
|
{
|
||||||
@@ -29,6 +29,11 @@ namespace WireMock.Net.StandAlone.NETCoreApp
|
|||||||
Log.ErrorFormat(formatString, args);
|
Log.ErrorFormat(formatString, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Error(string message, Exception exception)
|
||||||
|
{
|
||||||
|
Log.Error(message, exception);
|
||||||
|
}
|
||||||
|
|
||||||
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);
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using JetBrains.Annotations;
|
using System;
|
||||||
|
using JetBrains.Annotations;
|
||||||
using WireMock.Admin.Requests;
|
using WireMock.Admin.Requests;
|
||||||
|
|
||||||
namespace WireMock.Logging
|
namespace WireMock.Logging
|
||||||
@@ -45,6 +46,14 @@ namespace WireMock.Logging
|
|||||||
[StringFormatMethod("formatString")]
|
[StringFormatMethod("formatString")]
|
||||||
void Error([NotNull] string formatString, [NotNull] params object[] args);
|
void Error([NotNull] string formatString, [NotNull] params object[] args);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Writes the message at the Error level using the specified exception.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="message">The message.</param>
|
||||||
|
/// <param name="exception">The exception.</param>
|
||||||
|
[PublicAPI]
|
||||||
|
void Error([NotNull] string message, [NotNull] Exception exception);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Writes the LogEntryModel (LogRequestModel, LogResponseModel and more).
|
/// Writes the LogEntryModel (LogRequestModel, LogResponseModel and more).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -36,12 +36,27 @@ namespace WireMock.Logging
|
|||||||
Console.WriteLine(Format("Warn", formatString, args));
|
Console.WriteLine(Format("Warn", formatString, args));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <see cref="IWireMockLogger.Error"/>
|
/// <see cref="IWireMockLogger.Error(string, object[])"/>
|
||||||
public void Error(string formatString, params object[] args)
|
public void Error(string formatString, params object[] args)
|
||||||
{
|
{
|
||||||
Console.WriteLine(Format("Error", formatString, args));
|
Console.WriteLine(Format("Error", formatString, args));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <see cref="IWireMockLogger.Error(string, Exception)"/>
|
||||||
|
public void Error(string formatString, Exception exception)
|
||||||
|
{
|
||||||
|
Console.WriteLine(Format("Error", formatString, exception.Message));
|
||||||
|
|
||||||
|
if (exception is AggregateException ae)
|
||||||
|
{
|
||||||
|
ae.Handle(ex =>
|
||||||
|
{
|
||||||
|
Console.WriteLine(Format("Error", "Exception {0}", exception.Message));
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <see cref="IWireMockLogger.DebugRequestResponse"/>
|
/// <see cref="IWireMockLogger.DebugRequestResponse"/>
|
||||||
public void DebugRequestResponse(LogEntryModel logEntryModel, bool isAdminRequest)
|
public void DebugRequestResponse(LogEntryModel logEntryModel, bool isAdminRequest)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using WireMock.Admin.Requests;
|
using System;
|
||||||
|
using WireMock.Admin.Requests;
|
||||||
|
|
||||||
namespace WireMock.Logging
|
namespace WireMock.Logging
|
||||||
{
|
{
|
||||||
@@ -26,12 +27,18 @@ namespace WireMock.Logging
|
|||||||
// Log nothing
|
// Log nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <see cref="IWireMockLogger.Error"/>
|
/// <see cref="IWireMockLogger.Error(string, object[])"/>
|
||||||
public void Error(string formatString, params object[] args)
|
public void Error(string formatString, params object[] args)
|
||||||
{
|
{
|
||||||
// Log nothing
|
// Log nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <see cref="IWireMockLogger.Error(string, Exception)"/>
|
||||||
|
public void Error(string formatString, Exception exception)
|
||||||
|
{
|
||||||
|
// Log nothing
|
||||||
|
}
|
||||||
|
|
||||||
/// <see cref="IWireMockLogger.DebugRequestResponse"/>
|
/// <see cref="IWireMockLogger.DebugRequestResponse"/>
|
||||||
public void DebugRequestResponse(LogEntryModel logEntryModel, bool isAdminRequest)
|
public void DebugRequestResponse(LogEntryModel logEntryModel, bool isAdminRequest)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ namespace WireMock.Owin
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_options.Logger.Error("HttpStatusCode set to 500 {0}", ex);
|
_options.Logger.Error("HttpStatusCode set to 500", ex);
|
||||||
await _responseMapper.MapAsync(ResponseMessageBuilder.Create(JsonConvert.SerializeObject(ex), 500), ctx.Response);
|
await _responseMapper.MapAsync(ResponseMessageBuilder.Create(JsonConvert.SerializeObject(ex), 500), ctx.Response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -490,12 +490,12 @@ namespace WireMock.Server
|
|||||||
}
|
}
|
||||||
catch (ArgumentException a)
|
catch (ArgumentException a)
|
||||||
{
|
{
|
||||||
_settings.Logger.Error("HttpStatusCode set to 400 {0}", a);
|
_settings.Logger.Error("HttpStatusCode set to 400", a);
|
||||||
return ResponseMessageBuilder.Create(a.Message, 400);
|
return ResponseMessageBuilder.Create(a.Message, 400);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
_settings.Logger.Error("HttpStatusCode set to 500 {0}", e);
|
_settings.Logger.Error("HttpStatusCode set to 500", e);
|
||||||
return ResponseMessageBuilder.Create(e.ToString(), 500);
|
return ResponseMessageBuilder.Create(e.ToString(), 500);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user