| | | 1 | | using System; |
| | | 2 | | using Newtonsoft.Json; |
| | | 3 | | using WireMock.Admin.Requests; |
| | | 4 | | |
| | | 5 | | namespace WireMock.Logging |
| | | 6 | | { |
| | | 7 | | /// <summary> |
| | | 8 | | /// WireMockConsoleLogger which logs to Console |
| | | 9 | | /// </summary> |
| | | 10 | | /// <seealso cref="IWireMockLogger" /> |
| | | 11 | | public class WireMockConsoleLogger : IWireMockLogger |
| | | 12 | | { |
| | | 13 | | /// <summary> |
| | | 14 | | /// Initializes a new instance of the <see cref="WireMockConsoleLogger"/> class. |
| | | 15 | | /// </summary> |
| | 0 | 16 | | public WireMockConsoleLogger() |
| | 0 | 17 | | { |
| | 0 | 18 | | Console.OutputEncoding = System.Text.Encoding.UTF8; |
| | 0 | 19 | | } |
| | | 20 | | |
| | | 21 | | /// <see cref="IWireMockLogger.Debug"/> |
| | | 22 | | public void Debug(string formatString, params object[] args) |
| | 0 | 23 | | { |
| | 0 | 24 | | Console.WriteLine(Format("Debug", formatString, args)); |
| | 0 | 25 | | } |
| | | 26 | | |
| | | 27 | | /// <see cref="IWireMockLogger.Info"/> |
| | | 28 | | public void Info(string formatString, params object[] args) |
| | 0 | 29 | | { |
| | 0 | 30 | | Console.WriteLine(Format("Info", formatString, args)); |
| | 0 | 31 | | } |
| | | 32 | | |
| | | 33 | | /// <see cref="IWireMockLogger.Warn"/> |
| | | 34 | | public void Warn(string formatString, params object[] args) |
| | 0 | 35 | | { |
| | 0 | 36 | | Console.WriteLine(Format("Warn", formatString, args)); |
| | 0 | 37 | | } |
| | | 38 | | |
| | | 39 | | /// <see cref="IWireMockLogger.Error"/> |
| | | 40 | | public void Error(string formatString, params object[] args) |
| | 0 | 41 | | { |
| | 0 | 42 | | Console.WriteLine(Format("Error", formatString, args)); |
| | 0 | 43 | | } |
| | | 44 | | |
| | | 45 | | /// <see cref="IWireMockLogger.DebugRequestResponse"/> |
| | | 46 | | public void DebugRequestResponse(LogEntryModel logEntryModel, bool isAdminRequest) |
| | 0 | 47 | | { |
| | 0 | 48 | | string message = JsonConvert.SerializeObject(logEntryModel, Formatting.Indented); |
| | 0 | 49 | | Console.WriteLine(Format("DebugRequestResponse", "Admin[{0}] {1}", isAdminRequest, message)); |
| | 0 | 50 | | } |
| | | 51 | | |
| | | 52 | | private static string Format(string level, string formatString, params object[] args) |
| | 0 | 53 | | { |
| | 0 | 54 | | var message = args.Length > 0 ? string.Format(formatString, args) : formatString; |
| | | 55 | | |
| | 0 | 56 | | return $"{DateTime.UtcNow} [{level}] : {message}"; |
| | 0 | 57 | | } |
| | | 58 | | } |
| | | 59 | | } |