Skip to content
Snippets Groups Projects
Commit c6c0349e authored by Niko Ehrenfeuchter's avatar Niko Ehrenfeuchter :keyboard:
Browse files

Set NLog log level according to service configuration.

Refers to #3
parent dca805e6
No related branches found
No related tags found
No related merge requests found
...@@ -68,7 +68,7 @@ namespace ATxService ...@@ -68,7 +68,7 @@ namespace ATxService
public AutoTx() { public AutoTx() {
InitializeComponent(); InitializeComponent();
SetupFileLogging(); SetupFileLogging(LogLevel.Debug);
Log.Info("=========================================================================="); Log.Info("==========================================================================");
Log.Info("Attempting to start {0} service...", ServiceName); Log.Info("Attempting to start {0} service...", ServiceName);
CreateEventLog(); CreateEventLog();
...@@ -79,9 +79,10 @@ namespace ATxService ...@@ -79,9 +79,10 @@ namespace ATxService
/// <summary> /// <summary>
/// Set up NLog logging: targets, rules... /// Set up NLog logging: targets, rules...
/// </summary> /// </summary>
private void SetupFileLogging() { private void SetupFileLogging(LogLevel logLevel) {
var logConfig = new LoggingConfiguration(); var logConfig = new LoggingConfiguration();
var fileTarget = new FileTarget { var fileTarget = new FileTarget {
Name = "file",
FileName = ServiceName + ".log", FileName = ServiceName + ".log",
ArchiveAboveSize = 1 * Conv.MegaBytes, ArchiveAboveSize = 1 * Conv.MegaBytes,
ArchiveFileName = ServiceName + ".{#}.log", ArchiveFileName = ServiceName + ".{#}.log",
...@@ -90,7 +91,7 @@ namespace ATxService ...@@ -90,7 +91,7 @@ namespace ATxService
Layout = LogFormatDefault, Layout = LogFormatDefault,
}; };
logConfig.AddTarget("file", fileTarget); logConfig.AddTarget("file", fileTarget);
var logRuleFile = new LoggingRule("*", LogLevel.Debug, fileTarget); var logRuleFile = new LoggingRule("*", logLevel, fileTarget);
logConfig.LoggingRules.Add(logRuleFile); logConfig.LoggingRules.Add(logRuleFile);
LogManager.Configuration = logConfig; LogManager.Configuration = logConfig;
} }
...@@ -245,6 +246,9 @@ namespace ATxService ...@@ -245,6 +246,9 @@ namespace ATxService
/// Check if loaded configuration is valid, print a summary to the log. /// Check if loaded configuration is valid, print a summary to the log.
/// </summary> /// </summary>
private void CheckConfiguration() { private void CheckConfiguration() {
if (!_config.Debug)
SetupFileLogging(LogLevel.Info);
// non-critical / optional configuration parameters: // non-critical / optional configuration parameters:
if (!string.IsNullOrWhiteSpace(_config.SmtpHost)) if (!string.IsNullOrWhiteSpace(_config.SmtpHost))
SetupMailLogging(); SetupMailLogging();
...@@ -509,7 +513,6 @@ namespace ATxService ...@@ -509,7 +513,6 @@ namespace ATxService
#endregion #endregion
#region transfer tasks #region transfer tasks
/// <summary> /// <summary>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment