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

More mail logging configuration.

Refers to #3
parent 225926c0
No related branches found
No related tags found
No related merge requests found
...@@ -20,6 +20,8 @@ namespace AutoTx ...@@ -20,6 +20,8 @@ namespace AutoTx
#region global variables #region global variables
private static readonly Logger Log = LogManager.GetCurrentClassLogger(); private static readonly Logger Log = LogManager.GetCurrentClassLogger();
private const string LogFormatDefault = @"${date:format=yyyy-MM-dd HH\:mm\:ss} [${level}] ${message}";
// private const string LogFormatDefault = @"${date:format=yyyy-MM-dd HH\:mm\:ss} [${level}] (${logger}) ${message}"
// naming convention: variables ending with "Path" are strings, variables // naming convention: variables ending with "Path" are strings, variables
// ending with "Dir" are DirectoryInfo objects // ending with "Dir" are DirectoryInfo objects
...@@ -89,8 +91,7 @@ namespace AutoTx ...@@ -89,8 +91,7 @@ namespace AutoTx
ArchiveFileName = ServiceName + ".{#}.log", ArchiveFileName = ServiceName + ".{#}.log",
MaxArchiveFiles = 9, MaxArchiveFiles = 9,
KeepFileOpen = true, KeepFileOpen = true,
Layout = @"${date:format=yyyy-MM-dd HH\:mm\:ss} [${level}] ${message}", Layout = LogFormatDefault,
// Layout = @"${date:format=yyyy-MM-dd HH\:mm\:ss} [${level}] (${logger}) ${message}"
}; };
logConfig.AddTarget("file", fileTarget); logConfig.AddTarget("file", fileTarget);
var logRuleFile = new LoggingRule("*", LogLevel.Debug, fileTarget); var logRuleFile = new LoggingRule("*", LogLevel.Debug, fileTarget);
...@@ -113,6 +114,11 @@ namespace AutoTx ...@@ -113,6 +114,11 @@ namespace AutoTx
string.IsNullOrWhiteSpace(_config.AdminEmailAdress)) string.IsNullOrWhiteSpace(_config.AdminEmailAdress))
return; return;
var subject = string.Format("{0} - {1} - Admin Notification",
ServiceName, Environment.MachineName);
var body = string.Format("Notification from '{0}' ({1})\n\n{2}",
_config.HostAlias, Environment.MachineName, LogFormatDefault);
var logConfig = LogManager.Configuration; var logConfig = LogManager.Configuration;
var mailTargetFatal = new MailTarget { var mailTargetFatal = new MailTarget {
Name = "mailfatal", Name = "mailfatal",
...@@ -120,6 +126,8 @@ namespace AutoTx ...@@ -120,6 +126,8 @@ namespace AutoTx
SmtpPort = _config.SmtpPort, SmtpPort = _config.SmtpPort,
From = _config.EmailFrom, From = _config.EmailFrom,
To = _config.AdminEmailAdress, To = _config.AdminEmailAdress,
Subject = subject,
Body = body,
}; };
logConfig.AddTarget(mailTargetFatal); logConfig.AddTarget(mailTargetFatal);
logConfig.AddRuleForOneLevel(LogLevel.Fatal, mailTargetFatal); logConfig.AddRuleForOneLevel(LogLevel.Fatal, mailTargetFatal);
...@@ -131,6 +139,8 @@ namespace AutoTx ...@@ -131,6 +139,8 @@ namespace AutoTx
SmtpPort = _config.SmtpPort, SmtpPort = _config.SmtpPort,
From = _config.EmailFrom, From = _config.EmailFrom,
To = _config.AdminDebugEmailAdress, To = _config.AdminDebugEmailAdress,
Subject = subject,
Body = body,
}; };
logConfig.AddTarget(mailTargetError); logConfig.AddTarget(mailTargetError);
logConfig.AddRuleForOneLevel(LogLevel.Error, mailTargetError); logConfig.AddRuleForOneLevel(LogLevel.Error, mailTargetError);
......
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