diff --git a/BTCPayServer/BTCPayServer.csproj b/BTCPayServer/BTCPayServer.csproj
index 2a4ff0d3a..681caa34e 100644
--- a/BTCPayServer/BTCPayServer.csproj
+++ b/BTCPayServer/BTCPayServer.csproj
@@ -53,6 +53,9 @@
+
+
+
diff --git a/BTCPayServer/Configuration/DefaultConfiguration.cs b/BTCPayServer/Configuration/DefaultConfiguration.cs
index c8f65069e..2cd86285a 100644
--- a/BTCPayServer/Configuration/DefaultConfiguration.cs
+++ b/BTCPayServer/Configuration/DefaultConfiguration.cs
@@ -39,6 +39,7 @@ namespace BTCPayServer.Configuration
app.Option("--sshkeyfile", "SSH private key file to manage BTCPay (default: empty)", CommandOptionType.SingleValue);
app.Option("--sshkeyfilepassword", "Password of the SSH keyfile (default: empty)", CommandOptionType.SingleValue);
app.Option("--sshtrustedfingerprints", "SSH Host public key fingerprint or sha256 (default: empty, it will allow untrusted connections)", CommandOptionType.SingleValue);
+ app.Option("--debuglog", "A rolling log file for debug messages.", CommandOptionType.SingleValue);
foreach (var network in provider.GetAll())
{
var crypto = network.CryptoCode.ToLowerInvariant();
diff --git a/BTCPayServer/Program.cs b/BTCPayServer/Program.cs
index 8c6322285..2b1916c9e 100644
--- a/BTCPayServer/Program.cs
+++ b/BTCPayServer/Program.cs
@@ -15,11 +15,14 @@ using System.Collections.Generic;
using System.Collections;
using Microsoft.AspNetCore.Hosting.Server.Features;
using System.Threading;
+using Serilog;
namespace BTCPayServer
{
class Program
{
+ private const long MAX_DEBUG_LOG_FILE_SIZE = 2000000; // If debug log is in use roll it every N MB.
+
static void Main(string[] args)
{
ServicePointManager.DefaultConnectionLimit = 100;
@@ -31,7 +34,7 @@ namespace BTCPayServer
var logger = loggerFactory.CreateLogger("Configuration");
try
{
- // This is the only way toat LoadArgs can print to console. Because LoadArgs is called by the HostBuilder before Logs.Configure is called
+ // This is the only way that 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);
if (conf == null)
return;
@@ -50,6 +53,20 @@ namespace BTCPayServer
l.AddFilter("Microsoft", LogLevel.Error);
l.AddFilter("Microsoft.AspNetCore.Antiforgery.Internal", LogLevel.Critical);
l.AddProvider(new CustomConsoleLogProvider(processor));
+
+ // Use Serilog for debug log file.
+ string debugLogFile = conf.GetOrDefault("debuglog", null);
+ if (String.IsNullOrEmpty(debugLogFile) == false)
+ {
+ Serilog.Log.Logger = new LoggerConfiguration()
+ .Enrich.FromLogContext()
+ .MinimumLevel.Debug()
+ .WriteTo.File(debugLogFile, rollingInterval: RollingInterval.Day, fileSizeLimitBytes: MAX_DEBUG_LOG_FILE_SIZE, rollOnFileSizeLimit: true, retainedFileCountLimit: 1)
+ .CreateLogger();
+
+ l.AddSerilog(Serilog.Log.Logger);
+ logger.LogDebug($"Debug log file configured for {debugLogFile}.");
+ }
})
.UseStartup()
.Build();
@@ -73,6 +90,7 @@ namespace BTCPayServer
Logs.Configuration.LogError("Configuration error");
if (host != null)
host.Dispose();
+ Serilog.Log.CloseAndFlush();
loggerProvider.Dispose();
}
}
diff --git a/BTCPayServer/Properties/launchSettings.json b/BTCPayServer/Properties/launchSettings.json
index f63e1f444..6555e2c8e 100644
--- a/BTCPayServer/Properties/launchSettings.json
+++ b/BTCPayServer/Properties/launchSettings.json
@@ -2,6 +2,7 @@
"profiles": {
"Docker-Regtest": {
"commandName": "Project",
+ "commandLineArgs": "--debuglog debug.log",
"launchBrowser": true,
"environmentVariables": {
"BTCPAY_NETWORK": "regtest",