-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNotification.cs
More file actions
44 lines (40 loc) · 1.51 KB
/
Notification.cs
File metadata and controls
44 lines (40 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using System;
using System.Net.Mail;
namespace ServiceMonitor
{
public class Notification
{
public static void SendEmail(Service service, SMTPConfig smtpConfiguration, double memorySize, bool restartSuccess)
{
SmtpClient client = new SmtpClient(smtpConfiguration.Server);
string from = smtpConfiguration.FromEmail;
string to = smtpConfiguration.ToEmail;
string subject = $"Service {service.Name} -";
if (restartSuccess)
{
subject += "Memory Threshold Exceeded";
}
else
{
subject += "WARNING - Service failed to restart";
}
string message = $"Service:{service.Name}\nMemory Threshold:{service.MemoryLimitMB}MB\nCurrent Memory Usage:{memorySize}MB";
string messageFooter =
"\n\n\n" +
"-------------------------------------" +
$"\nSent from: {Environment.MachineName}" +
$"\nDate Time:{DateTime.Now}" +
"\n-------------------------------------";
if (restartSuccess)
{
message += $"\nService was stopped, files cleared, and service restarted correctly.";
}
else
{
message += $"\n WARNING: Service was stopped and failed to restart correctly!";
}
message += messageFooter;
client.Send(from, to, subject, message);
}
}
}