diff --git a/ATxCommon/Serializables/ServiceConfig.cs b/ATxCommon/Serializables/ServiceConfig.cs index 2fd864a723e9e01b85ac09e3a841292d2b4fe81a..378bf1a5bd4bab786df1bd10fa1a75562c1f3061 100644 --- a/ATxCommon/Serializables/ServiceConfig.cs +++ b/ATxCommon/Serializables/ServiceConfig.cs @@ -74,9 +74,9 @@ namespace ATxCommon.Serializables #region optional configuration parameters /// <summary> - /// Switch on debug log messages. Default: false. + /// NLog log level, one of "Warn", "Info", "Debug", "Trace". Default: "Info" /// </summary> - public bool Debug { get; set; } = false; + public string LogLevel { get; set; } = "Info"; /// <summary> /// Enable debug messages from the RoboSharp library. Default: false. @@ -436,6 +436,14 @@ namespace ATxCommon.Serializables if (!c.DestinationDirectory.StartsWith(@"\\")) SubOptimal(c.DestinationDirectory, "DestinationDirectory", "is not a UNC path!"); + // LogLevel + var validLogLevels = new List<string> {"Warn", "Info", "Debug", "Trace"}; + if (!validLogLevels.Contains(c.LogLevel)) { + SubOptimal(c.LogLevel, "LogLevel", "is invalid, using 'Debug'. Valid options: " + + string.Join(", ", validLogLevels)); + c.LogLevel = "Debug"; + } + if (string.IsNullOrWhiteSpace(errmsg)) return; @@ -461,7 +469,7 @@ namespace ATxCommon.Serializables $"MinAvailableMemory: {MinAvailableMemory} MB\n" + "\n" + "############### OPTIONAL PARAMETERS ###############\n" + - $"Debug: {Debug}\n" + + $"LogLevel: {LogLevel}\n" + $"ServiceTimer: {ServiceTimer} ms\n" + $"MarkerFile: {MarkerFile}\n" + $"GracePeriod: {GracePeriod} days (" + diff --git a/ATxService/AutoTx.cs b/ATxService/AutoTx.cs index e8ebfb35a9ab44a4a3bfecf250041b8371655af3..fbb31e9c035df62c482072c44f62c1a5cc051284 100644 --- a/ATxService/AutoTx.cs +++ b/ATxService/AutoTx.cs @@ -82,7 +82,7 @@ namespace ATxService /// </summary> public AutoTx() { InitializeComponent(); - SetupFileLogging(LogLevel.Debug); + SetupFileLogging(); Log.Info("=".PadLeft(80, '=')); Log.Info("Attempting to start {0} service...", ServiceName); CreateEventLog(); @@ -98,7 +98,22 @@ namespace ATxService /// <summary> /// Set up NLog logging: targets, rules... /// </summary> - private void SetupFileLogging(LogLevel logLevel) { + private void SetupFileLogging(string logLevelName = "Debug") { + LogLevel logLevel; + switch (logLevelName) { + case "Warn": + logLevel = LogLevel.Warn; + break; + case "Info": + logLevel = LogLevel.Info; + break; + case "Trace": + logLevel = LogLevel.Trace; + break; + default: + logLevel = LogLevel.Debug; + break; + } var logConfig = new LoggingConfiguration(); var fileTarget = new FileTarget { Name = "file", @@ -234,6 +249,7 @@ namespace ATxService // this should terminate the service process: throw new Exception("Error loading configuration."); } + SetupFileLogging(_config.LogLevel); } /// <summary> @@ -259,9 +275,6 @@ namespace ATxService /// Check if loaded configuration is valid, print a summary to the log. /// </summary> private void CheckConfiguration() { - if (!_config.Debug) - SetupFileLogging(LogLevel.Info); - // non-critical / optional configuration parameters: if (!string.IsNullOrWhiteSpace(_config.SmtpHost)) SetupMailLogging(); diff --git a/Resources/conf/config.common.xml b/Resources/conf/config.common.xml index 16e7fa5463837f9d91590339d47ea64d7b7e358c..b472f537d85ea3649618349079d4d164e96f859f 100644 --- a/Resources/conf/config.common.xml +++ b/Resources/conf/config.common.xml @@ -30,8 +30,8 @@ <!-- OPTIONAL CONFIGURATION SETTINGS --> - <!-- Debug: enable or disable debug log messages --> - <Debug>true</Debug> + <!-- LogLevel: one of "Warn", "Info", "Debug", "Trace" --> + <LogLevel>Debug</LogLevel> <!-- DebugRoboSharp: enable debug messages from the RoboSharp library. --> <DebugRoboSharp>true</DebugRoboSharp>