mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-18 22:44:29 +01:00
Added Serilog file logger for debug file support. (#323)
This commit is contained in:
committed by
Nicolas Dorier
parent
e1751c4d91
commit
d7785fe2d2
@@ -53,6 +53,9 @@
|
|||||||
<PackageReference Include="NicolasDorier.RateLimits" Version="1.0.0.3" />
|
<PackageReference Include="NicolasDorier.RateLimits" Version="1.0.0.3" />
|
||||||
<PackageReference Include="NicolasDorier.StandardConfiguration" Version="1.0.0.18" />
|
<PackageReference Include="NicolasDorier.StandardConfiguration" Version="1.0.0.18" />
|
||||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="2.1.0" />
|
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="2.1.0" />
|
||||||
|
<PackageReference Include="Serilog" Version="2.7.1" />
|
||||||
|
<PackageReference Include="Serilog.AspNetCore" Version="2.1.1" />
|
||||||
|
<PackageReference Include="Serilog.Sinks.File" Version="4.0.0" />
|
||||||
<PackageReference Include="SSH.NET" Version="2016.1.0" />
|
<PackageReference Include="SSH.NET" Version="2016.1.0" />
|
||||||
<PackageReference Include="System.Xml.XmlSerializer" Version="4.3.0" />
|
<PackageReference Include="System.Xml.XmlSerializer" Version="4.3.0" />
|
||||||
<PackageReference Include="Text.Analyzers" Version="2.6.0" />
|
<PackageReference Include="Text.Analyzers" Version="2.6.0" />
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ namespace BTCPayServer.Configuration
|
|||||||
app.Option("--sshkeyfile", "SSH private key file to manage BTCPay (default: empty)", CommandOptionType.SingleValue);
|
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("--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("--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())
|
foreach (var network in provider.GetAll())
|
||||||
{
|
{
|
||||||
var crypto = network.CryptoCode.ToLowerInvariant();
|
var crypto = network.CryptoCode.ToLowerInvariant();
|
||||||
|
|||||||
@@ -15,11 +15,14 @@ using System.Collections.Generic;
|
|||||||
using System.Collections;
|
using System.Collections;
|
||||||
using Microsoft.AspNetCore.Hosting.Server.Features;
|
using Microsoft.AspNetCore.Hosting.Server.Features;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
using Serilog;
|
||||||
|
|
||||||
namespace BTCPayServer
|
namespace BTCPayServer
|
||||||
{
|
{
|
||||||
class Program
|
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)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
ServicePointManager.DefaultConnectionLimit = 100;
|
ServicePointManager.DefaultConnectionLimit = 100;
|
||||||
@@ -31,7 +34,7 @@ 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
|
// 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);
|
var conf = new DefaultConfiguration() { Logger = logger }.CreateConfiguration(args);
|
||||||
if (conf == null)
|
if (conf == null)
|
||||||
return;
|
return;
|
||||||
@@ -50,6 +53,20 @@ namespace BTCPayServer
|
|||||||
l.AddFilter("Microsoft", LogLevel.Error);
|
l.AddFilter("Microsoft", LogLevel.Error);
|
||||||
l.AddFilter("Microsoft.AspNetCore.Antiforgery.Internal", LogLevel.Critical);
|
l.AddFilter("Microsoft.AspNetCore.Antiforgery.Internal", LogLevel.Critical);
|
||||||
l.AddProvider(new CustomConsoleLogProvider(processor));
|
l.AddProvider(new CustomConsoleLogProvider(processor));
|
||||||
|
|
||||||
|
// Use Serilog for debug log file.
|
||||||
|
string debugLogFile = conf.GetOrDefault<string>("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<Startup>()
|
.UseStartup<Startup>()
|
||||||
.Build();
|
.Build();
|
||||||
@@ -73,6 +90,7 @@ namespace BTCPayServer
|
|||||||
Logs.Configuration.LogError("Configuration error");
|
Logs.Configuration.LogError("Configuration error");
|
||||||
if (host != null)
|
if (host != null)
|
||||||
host.Dispose();
|
host.Dispose();
|
||||||
|
Serilog.Log.CloseAndFlush();
|
||||||
loggerProvider.Dispose();
|
loggerProvider.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
"profiles": {
|
"profiles": {
|
||||||
"Docker-Regtest": {
|
"Docker-Regtest": {
|
||||||
"commandName": "Project",
|
"commandName": "Project",
|
||||||
|
"commandLineArgs": "--debuglog debug.log",
|
||||||
"launchBrowser": true,
|
"launchBrowser": true,
|
||||||
"environmentVariables": {
|
"environmentVariables": {
|
||||||
"BTCPAY_NETWORK": "regtest",
|
"BTCPAY_NETWORK": "regtest",
|
||||||
|
|||||||
Reference in New Issue
Block a user