mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-10 02:43:33 +02:00
* Replace log4net by custom logger * WireMockNullLogger
This commit is contained in:
@@ -113,7 +113,7 @@ namespace WireMock.Server
|
||||
|
||||
foreach (string filename in Directory.EnumerateFiles(folder).OrderBy(f => f))
|
||||
{
|
||||
Log.InfoFormat("Reading Static MappingFile : '{0}'", filename);
|
||||
_logger.Info("Reading Static MappingFile : '{0}'", filename);
|
||||
ReadStaticMappingAndAddOrUpdate(filename);
|
||||
}
|
||||
}
|
||||
@@ -135,22 +135,22 @@ namespace WireMock.Server
|
||||
return;
|
||||
}
|
||||
|
||||
Log.InfoFormat("Watching folder '{0}' for new, updated and deleted MappingFiles.", folder);
|
||||
_logger.Info("Watching folder '{0}' for new, updated and deleted MappingFiles.", folder);
|
||||
|
||||
var watcher = new EnhancedFileSystemWatcher(folder, "*.json", 1000);
|
||||
watcher.Created += (sender, args) =>
|
||||
{
|
||||
Log.InfoFormat("New MappingFile created : '{0}'", args.FullPath);
|
||||
_logger.Info("New MappingFile created : '{0}'", args.FullPath);
|
||||
ReadStaticMappingAndAddOrUpdate(args.FullPath);
|
||||
};
|
||||
watcher.Changed += (sender, args) =>
|
||||
{
|
||||
Log.InfoFormat("New MappingFile updated : '{0}'", args.FullPath);
|
||||
_logger.Info("New MappingFile updated : '{0}'", args.FullPath);
|
||||
ReadStaticMappingAndAddOrUpdate(args.FullPath);
|
||||
};
|
||||
watcher.Deleted += (sender, args) =>
|
||||
{
|
||||
Log.InfoFormat("New MappingFile deleted : '{0}'", args.FullPath);
|
||||
_logger.Info("New MappingFile deleted : '{0}'", args.FullPath);
|
||||
string filenameWithoutExtension = Path.GetFileNameWithoutExtension(args.FullPath);
|
||||
|
||||
if (Guid.TryParse(filenameWithoutExtension, out Guid guidFromFilename))
|
||||
@@ -288,7 +288,7 @@ namespace WireMock.Server
|
||||
|
||||
if (mapping == null)
|
||||
{
|
||||
Log.Warn("HttpStatusCode set to 404 : Mapping not found");
|
||||
_logger.Warn("HttpStatusCode set to 404 : Mapping not found");
|
||||
return new ResponseMessage { StatusCode = 404, Body = "Mapping not found" };
|
||||
}
|
||||
|
||||
@@ -343,7 +343,7 @@ namespace WireMock.Server
|
||||
string filename = !string.IsNullOrEmpty(mapping.Title) ? SanitizeFileName(mapping.Title) : mapping.Guid.ToString();
|
||||
|
||||
string filePath = Path.Combine(folder, filename + ".json");
|
||||
Log.InfoFormat("Saving Mapping to file {0}", filePath);
|
||||
_logger.Info("Saving Mapping to file {0}", filePath);
|
||||
|
||||
File.WriteAllText(filePath, JsonConvert.SerializeObject(model, _settings));
|
||||
}
|
||||
@@ -374,12 +374,12 @@ namespace WireMock.Server
|
||||
}
|
||||
catch (ArgumentException a)
|
||||
{
|
||||
Log.Error("HttpStatusCode set to 400", a);
|
||||
_logger.Error("HttpStatusCode set to 400 {0}", a);
|
||||
return new ResponseMessage { StatusCode = 400, Body = a.Message };
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error("HttpStatusCode set to 500", e);
|
||||
_logger.Error("HttpStatusCode set to 500 {0}", e);
|
||||
return new ResponseMessage { StatusCode = 500, Body = e.ToString() };
|
||||
}
|
||||
|
||||
@@ -449,8 +449,8 @@ namespace WireMock.Server
|
||||
|
||||
if (entry == null)
|
||||
{
|
||||
Log.Warn("HttpStatusCode set to 404 : Request not found");
|
||||
return new ResponseMessage {StatusCode = 404, Body = "Request not found"};
|
||||
_logger.Warn("HttpStatusCode set to 404 : Request not found");
|
||||
return new ResponseMessage { StatusCode = 404, Body = "Request not found" };
|
||||
}
|
||||
|
||||
var model = ToLogEntryModel(entry);
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using JetBrains.Annotations;
|
||||
using log4net;
|
||||
using Newtonsoft.Json;
|
||||
using WireMock.Http;
|
||||
using WireMock.Logging;
|
||||
using WireMock.Matchers;
|
||||
using WireMock.Matchers.Request;
|
||||
using WireMock.RequestBuilders;
|
||||
@@ -23,7 +22,7 @@ namespace WireMock.Server
|
||||
/// </summary>
|
||||
public partial class FluentMockServer : IDisposable
|
||||
{
|
||||
private static readonly ILog Log = LogManager.GetLogger(typeof(FluentMockServer));
|
||||
private readonly IWireMockLogger _logger;
|
||||
private const int ServerStartDelay = 100;
|
||||
private readonly IOwinSelfHost _httpServer;
|
||||
private readonly WireMockMiddlewareOptions _options = new WireMockMiddlewareOptions();
|
||||
@@ -158,7 +157,10 @@ namespace WireMock.Server
|
||||
|
||||
private FluentMockServer(IFluentMockServerSettings settings)
|
||||
{
|
||||
Log.DebugFormat("WireMock.Net server settings {0}", JsonConvert.SerializeObject(settings, Formatting.Indented));
|
||||
settings.Logger = settings.Logger ?? new WireMockConsoleLogger();
|
||||
_logger = settings.Logger;
|
||||
|
||||
_logger.Debug("WireMock.Net server settings {0}", JsonConvert.SerializeObject(settings, Formatting.Indented));
|
||||
|
||||
if (settings.Urls != null)
|
||||
{
|
||||
@@ -172,6 +174,7 @@ namespace WireMock.Server
|
||||
|
||||
_options.PreWireMockMiddlewareInit = settings.PreWireMockMiddlewareInit;
|
||||
_options.PostWireMockMiddlewareInit = settings.PostWireMockMiddlewareInit;
|
||||
_options.Logger = _logger;
|
||||
|
||||
#if NETSTANDARD
|
||||
_httpServer = new AspNetCoreSelfHost(_options, Urls);
|
||||
@@ -318,7 +321,7 @@ namespace WireMock.Server
|
||||
[PublicAPI]
|
||||
public void AllowPartialMapping(bool allow = true)
|
||||
{
|
||||
Log.InfoFormat("AllowPartialMapping is set to {0}", allow);
|
||||
_logger.Info("AllowPartialMapping is set to {0}", allow);
|
||||
_options.AllowPartialMapping = allow;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user