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
public AutoTx() {
InitializeComponent();
SetupFileLogging();
SetupFileLogging(LogLevel.Debug);
Log.Info("==========================================================================");
Log.Info("Attempting to start {0} service...", ServiceName);
CreateEventLog();
......@@ -79,9 +79,10 @@ namespace ATxService
/// <summary>
/// Set up NLog logging: targets, rules...
/// </summary>
private void SetupFileLogging() {
private void SetupFileLogging(LogLevel logLevel) {
var logConfig = new LoggingConfiguration();
var fileTarget = new FileTarget {
Name = "file",
FileName = ServiceName + ".log",
ArchiveAboveSize = 1 * Conv.MegaBytes,
ArchiveFileName = ServiceName + ".{#}.log",
......@@ -90,7 +91,7 @@ namespace ATxService
Layout = LogFormatDefault,
};
logConfig.AddTarget("file", fileTarget);
var logRuleFile = new LoggingRule("*", LogLevel.Debug, fileTarget);
var logRuleFile = new LoggingRule("*", logLevel, fileTarget);
logConfig.LoggingRules.Add(logRuleFile);
LogManager.Configuration = logConfig;
}
......@@ -245,6 +246,9 @@ 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();
......@@ -509,7 +513,6 @@ namespace ATxService
#endregion
#region transfer tasks
/// <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