From ec0fc75d94b2b46948647391df035e8267bcd078 Mon Sep 17 00:00:00 2001
From: Niko Ehrenfeuchter <nikolaus.ehrenfeuchter@unibas.ch>
Date: Fri, 20 Jul 2018 09:33:52 +0200
Subject: [PATCH] Make load monitoring log level configurable

This introduces a new optional configuration parameter called
"LogLevelMonitoring" to adjust the log level of those messages related
to the load monitoring of the service.

Fixes #50
---
 ATxCommon/Serializables/ServiceConfig.cs | 28 ++++++++++++++++++++++++
 ATxCommon/Serializables/ServiceStatus.cs |  6 +++--
 Resources/conf/config.common.xml         |  3 +++
 3 files changed, 35 insertions(+), 2 deletions(-)

diff --git a/ATxCommon/Serializables/ServiceConfig.cs b/ATxCommon/Serializables/ServiceConfig.cs
index bf65c98..192fc32 100644
--- a/ATxCommon/Serializables/ServiceConfig.cs
+++ b/ATxCommon/Serializables/ServiceConfig.cs
@@ -78,6 +78,11 @@ namespace ATxCommon.Serializables
         /// </summary>
         public string LogLevel { get; set; } = "Info";
 
+        /// <summary>
+        /// Log level to use for performance monitoring messages. Default: "Trace"
+        /// </summary>
+        public string LogLevelMonitoring { get; set; } = "Trace";
+
         /// <summary>
         /// Enable debug messages from the RoboSharp library. Default: false.
         /// </summary>
@@ -255,6 +260,28 @@ namespace ATxCommon.Serializables
         [XmlIgnore]
         public string ErrorPath => Path.Combine(ManagedPath, "ERROR");
 
+        /// <summary>
+        /// The LogLevel to be used for performance monitoring messages.
+        /// </summary>
+        [XmlIgnore]
+        public LogLevel MonitoringLogLevel {
+            get {
+                switch (LogLevelMonitoring) {
+                    case "Warn":
+                        return global::NLog.LogLevel.Warn;
+                    case "Info":
+                        return global::NLog.LogLevel.Info;
+                    case "Debug":
+                        return global::NLog.LogLevel.Debug;
+                    case "Trace":
+                        return global::NLog.LogLevel.Trace;
+                    default:
+                        return global::NLog.LogLevel.Info;
+                }
+            }
+        }
+
+
         #endregion
 
 
@@ -470,6 +497,7 @@ namespace ATxCommon.Serializables
                 "\n" +
                 "############### OPTIONAL PARAMETERS ###############\n" +
                 $"LogLevel: {LogLevel}\n" +
+                $"LogLevelMonitoring: {LogLevelMonitoring}\n" +
                 $"ServiceTimer: {ServiceTimer} ms\n" +
                 $"MarkerFile: {MarkerFile}\n" +
                 $"GracePeriod: {GracePeriod} days (" +
diff --git a/ATxCommon/Serializables/ServiceStatus.cs b/ATxCommon/Serializables/ServiceStatus.cs
index 8e0ec88..fd01592 100644
--- a/ATxCommon/Serializables/ServiceStatus.cs
+++ b/ATxCommon/Serializables/ServiceStatus.cs
@@ -317,9 +317,11 @@ namespace ATxCommon.Serializables
             Serialize();
 
             if (suspended) {
-                Log.Trace("Service suspended. Reason(s): [{0}]", description);
+                Log.Log(_config.MonitoringLogLevel,
+                    "Service suspended. Reason(s): [{0}]", description);
             } else {
-                Log.Trace("Service resuming operation ({0}).", description);
+                Log.Log(_config.MonitoringLogLevel,
+                    "Service resuming operation ({0}).", description);
             }
         }
         
diff --git a/Resources/conf/config.common.xml b/Resources/conf/config.common.xml
index b472f53..7502066 100644
--- a/Resources/conf/config.common.xml
+++ b/Resources/conf/config.common.xml
@@ -33,6 +33,9 @@
     <!-- LogLevel: one of "Warn", "Info", "Debug", "Trace" -->
     <LogLevel>Debug</LogLevel>
 
+    <!-- LogLevelMonitoring: load monitoring log level, default "Trace". -->
+    <LogLevelMonitoring>Trace</LogLevelMonitoring>
+
     <!-- DebugRoboSharp: enable debug messages from the RoboSharp library. -->
     <DebugRoboSharp>true</DebugRoboSharp>
 
-- 
GitLab