Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
auto-tx
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
vamp
auto-tx
Commits
e5632220
Commit
e5632220
authored
7 years ago
by
Niko Ehrenfeuchter
Browse files
Options
Downloads
Patches
Plain Diff
Add mail logging targets for "Error" and "Fatal" levels.
Refers to
#3
parent
3b498e79
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
AutoTx/AutoTx.cs
+50
-2
50 additions, 2 deletions
AutoTx/AutoTx.cs
with
50 additions
and
2 deletions
AutoTx/AutoTx.cs
+
50
−
2
View file @
e5632220
...
...
@@ -76,7 +76,7 @@ namespace AutoTx
public
AutoTx
()
{
InitializeComponent
();
SetupLogging
();
Setup
File
Logging
();
CreateEventLog
();
LoadSettings
();
CreateIncomingDirectories
();
...
...
@@ -85,7 +85,7 @@ namespace AutoTx
/// <summary>
/// Set up NLog logging: targets, rules...
/// </summary>
private
void
SetupLogging
()
{
private
void
Setup
File
Logging
()
{
var
logConfig
=
new
LoggingConfiguration
();
var
fileTarget
=
new
FileTarget
{
FileName
=
ServiceName
+
".log"
,
...
...
@@ -102,6 +102,50 @@ namespace AutoTx
LogManager
.
Configuration
=
logConfig
;
}
/// <summary>
/// Configure logging to email targets.
///
/// Depending on the configuration, set up the logging via email. If no SmtpHost or no
/// AdminEmailAdress is configured, nothing will be done. If they're set in the config file,
/// a log target for messages with level "Fatal" will be configured. In addition, if the
/// AdminDebugEmailAdress is set, another target for "Error" level messages is configured
/// using this address as recipient.
/// </summary>
private
void
SetupMailLogging
()
{
try
{
if
(
string
.
IsNullOrWhiteSpace
(
_config
.
SmtpHost
)
||
string
.
IsNullOrWhiteSpace
(
_config
.
AdminEmailAdress
))
return
;
var
logConfig
=
LogManager
.
Configuration
;
var
mailTargetFatal
=
new
MailTarget
{
SmtpServer
=
_config
.
SmtpHost
,
SmtpPort
=
_config
.
SmtpPort
,
To
=
_config
.
AdminEmailAdress
,
Name
=
"mailfatal"
,
};
logConfig
.
AddTarget
(
mailTargetFatal
);
logConfig
.
AddRuleForOneLevel
(
LogLevel
.
Fatal
,
mailTargetFatal
);
if
(!
string
.
IsNullOrWhiteSpace
(
_config
.
AdminDebugEmailAdress
))
{
var
mailTargetError
=
new
MailTarget
{
SmtpServer
=
_config
.
SmtpHost
,
SmtpPort
=
_config
.
SmtpPort
,
To
=
_config
.
AdminDebugEmailAdress
,
Name
=
"mailerror"
,
};
logConfig
.
AddTarget
(
mailTargetError
);
logConfig
.
AddRuleForOneLevel
(
LogLevel
.
Error
,
mailTargetError
);
Log
.
Info
(
"Configured mail notification for 'Error' messages to {0}"
,
mailTargetError
.
To
);
}
Log
.
Info
(
"Configured mail notification for 'Fatal' messages to {0}"
,
mailTargetFatal
.
To
);
LogManager
.
Configuration
=
logConfig
;
}
catch
(
Exception
ex
)
{
Log
.
Error
(
"SetupMailLogging(): {0}"
,
ex
.
Message
);
}
}
/// <summary>
/// Create the event log if it doesn't exist yet.
/// </summary>
...
...
@@ -198,6 +242,10 @@ namespace AutoTx
/// Check if loaded configuration is valid, print a summary to the log.
/// </summary>
public
void
CheckConfiguration
()
{
// non-critical / optional configuration parameters:
if
(!
string
.
IsNullOrWhiteSpace
(
_config
.
SmtpHost
))
SetupMailLogging
();
var
configInvalid
=
false
;
if
(
CheckSpoolingDirectories
()
==
false
)
{
Log
.
Error
(
"ERROR checking spooling directories (incoming / managed)!"
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment