Fix missing logs

This commit is contained in:
nicolas.dorier
2018-07-01 15:52:11 +09:00
parent b7abc08c27
commit 06b02b8691
2 changed files with 15 additions and 3 deletions

View File

@@ -15,9 +15,14 @@ namespace BTCPayServer.Logging
} }
public static void Configure(ILoggerFactory factory) public static void Configure(ILoggerFactory factory)
{ {
Configuration = factory.CreateLogger("Configuration"); if (factory == null)
PayServer = factory.CreateLogger("PayServer"); Configure(new FuncLoggerFactory(n => NullLogger.Instance));
Events = factory.CreateLogger("Events"); else
{
Configuration = factory.CreateLogger("Configuration");
PayServer = factory.CreateLogger("PayServer");
Events = factory.CreateLogger("Events");
}
} }
public static ILogger Configuration public static ILogger Configuration
{ {

View File

@@ -31,9 +31,14 @@ namespace BTCPayServer
var logger = loggerFactory.CreateLogger("Configuration"); var logger = loggerFactory.CreateLogger("Configuration");
try try
{ {
// This is the only way toat LoadArgs can print to console. Because LoadArgs is called by the HostBuilder before Logs.Configure is called
var conf = new DefaultConfiguration() { Logger = logger }.CreateConfiguration(args); var conf = new DefaultConfiguration() { Logger = logger }.CreateConfiguration(args);
if (conf == null) if (conf == null)
return; return;
Logs.Configure(loggerFactory);
new BTCPayServerOptions().LoadArgs(conf);
Logs.Configure(null);
/////
host = new WebHostBuilder() host = new WebHostBuilder()
.UseKestrel() .UseKestrel()
@@ -64,6 +69,8 @@ namespace BTCPayServer
finally finally
{ {
processor.Dispose(); processor.Dispose();
if(host == null)
Logs.Configuration.LogError("Configuration error");
if (host != null) if (host != null)
host.Dispose(); host.Dispose();
loggerProvider.Dispose(); loggerProvider.Dispose();