mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-02-22 00:37:50 +01:00
Add WireMockNullLogger as valid commandline logger option (#845)
* Add WireMockNullLogger as valid commandline logger option * .
This commit is contained in:
@@ -5,56 +5,55 @@ using WireMock.Logging;
|
||||
using WireMock.Net.StandAlone;
|
||||
using WireMock.Server;
|
||||
|
||||
namespace WireMock.Net
|
||||
namespace WireMock.Net;
|
||||
|
||||
public class Program
|
||||
{
|
||||
public class Program
|
||||
private static readonly int SleepTime = 30000;
|
||||
private static readonly ILogger XLogger = LoggerFactory.Create(o =>
|
||||
{
|
||||
private static readonly int SleepTime = 30000;
|
||||
private static readonly ILogger xLogger = LoggerFactory.Create(o =>
|
||||
o.SetMinimumLevel(LogLevel.Debug);
|
||||
o.AddSimpleConsole(options =>
|
||||
{
|
||||
o.SetMinimumLevel(LogLevel.Debug);
|
||||
o.AddSimpleConsole(options =>
|
||||
{
|
||||
options.IncludeScopes = true;
|
||||
options.SingleLine = false;
|
||||
options.TimestampFormat = "yyyy-MM-ddTHH:mm:ss ";
|
||||
});
|
||||
}).CreateLogger("WireMock.Net");
|
||||
private static readonly IWireMockLogger Logger = new WireMockLogger(xLogger);
|
||||
options.IncludeScopes = true;
|
||||
options.SingleLine = false;
|
||||
options.TimestampFormat = "yyyy-MM-ddTHH:mm:ss ";
|
||||
});
|
||||
}).CreateLogger("WireMock.Net");
|
||||
private static readonly IWireMockLogger Logger = new WireMockLogger(XLogger);
|
||||
|
||||
private static WireMockServer Server;
|
||||
private static WireMockServer _server = null!;
|
||||
|
||||
static async Task Main(string[] args)
|
||||
static async Task Main(string[] args)
|
||||
{
|
||||
if (!StandAloneApp.TryStart(args, out _server!, Logger))
|
||||
{
|
||||
if (!StandAloneApp.TryStart(args, out Server, Logger))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Logger.Info("Press Ctrl+C to shut down");
|
||||
|
||||
Console.CancelKeyPress += (s, e) =>
|
||||
{
|
||||
Stop("CancelKeyPress");
|
||||
};
|
||||
|
||||
System.Runtime.Loader.AssemblyLoadContext.Default.Unloading += ctx =>
|
||||
{
|
||||
Stop("AssemblyLoadContext.Default.Unloading");
|
||||
};
|
||||
|
||||
while (true)
|
||||
{
|
||||
Logger.Info("Server running : {IsStarted}", Server.IsStarted);
|
||||
await Task.Delay(SleepTime).ConfigureAwait(false);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
private static void Stop(string why)
|
||||
Logger.Info("Press Ctrl+C to shut down");
|
||||
|
||||
Console.CancelKeyPress += (s, e) =>
|
||||
{
|
||||
Logger.Info("Server stopping because '{why}'", why);
|
||||
Server.Stop();
|
||||
Logger.Info("Server stopped");
|
||||
Stop("CancelKeyPress");
|
||||
};
|
||||
|
||||
System.Runtime.Loader.AssemblyLoadContext.Default.Unloading += ctx =>
|
||||
{
|
||||
Stop("AssemblyLoadContext.Default.Unloading");
|
||||
};
|
||||
|
||||
while (true)
|
||||
{
|
||||
Logger.Info("Server running : {0}", _server.IsStarted);
|
||||
await Task.Delay(SleepTime).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
private static void Stop(string why)
|
||||
{
|
||||
Logger.Info("Server stopping because '{0}'", why);
|
||||
_server.Stop();
|
||||
Logger.Info("Server stopped");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user