diff --git a/src/CryptoAgent/CryptoAgentSettings.cs b/src/CryptoAgent/CryptoAgentSettings.cs index 9dd16d3..a52774b 100644 --- a/src/CryptoAgent/CryptoAgentSettings.cs +++ b/src/CryptoAgent/CryptoAgentSettings.cs @@ -2,6 +2,7 @@ { public class CryptoAgentSettings { + public string LogFilePath { get; set; } public string IdentityServerUri { get; set; } public DatabaseSettings Database { get; set; } diff --git a/src/CryptoAgent/Program.cs b/src/CryptoAgent/Program.cs index 4c908c1..62b1d7f 100644 --- a/src/CryptoAgent/Program.cs +++ b/src/CryptoAgent/Program.cs @@ -1,4 +1,5 @@ using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Hosting; using Serilog; @@ -15,11 +16,18 @@ namespace Bit.CryptoAgent webBuilder.UseStartup(); webBuilder.ConfigureLogging((hostingContext, logging) => { + var settings = new CryptoAgentSettings(); + ConfigurationBinder.Bind( + hostingContext.Configuration.GetSection("CryptoAgentSettings"), settings); + var serilogConfig = new LoggerConfiguration() - .Enrich.FromLogContext() - .WriteTo.File("/etc/bitwarden/logs/log.txt", - rollOnFileSizeLimit: true, + .Enrich.FromLogContext(); + + if (!string.IsNullOrWhiteSpace(settings.LogFilePath)) + { + serilogConfig.WriteTo.File(settings.LogFilePath, rollOnFileSizeLimit: true, rollingInterval: RollingInterval.Day); + } var serilog = serilogConfig.CreateLogger(); logging.AddSerilog(serilog); diff --git a/src/CryptoAgent/appsettings.Development.json b/src/CryptoAgent/appsettings.Development.json index 5410f8b..d45511a 100644 --- a/src/CryptoAgent/appsettings.Development.json +++ b/src/CryptoAgent/appsettings.Development.json @@ -1,12 +1,11 @@ { "Logging": { "LogLevel": { - "Default": "Information", - "Microsoft": "Warning", - "Microsoft.Hosting.Lifetime": "Information" + "Default": "Information" } }, "cryptoAgentSettings": { - "identityServerUri": "http://localhost:33656/" + "identityServerUri": "http://localhost:33656/", + "logFilePath": null } } diff --git a/src/CryptoAgent/appsettings.json b/src/CryptoAgent/appsettings.json index 6f7cc7d..74094b4 100644 --- a/src/CryptoAgent/appsettings.json +++ b/src/CryptoAgent/appsettings.json @@ -8,6 +8,7 @@ }, "AllowedHosts": "*", "cryptoAgentSettings": { + "logFilePath": "/etc/bitwarden/logs/log.txt", "identityServerUri": "https://identity.bitwarden.com/", "database": { "provider": "json",