コード例 #1
0
        public List <string> RecipientList()
        {
            List <string> recipientList = new List <string>();

            if (!string.IsNullOrEmpty(EmailRecipients))
            {
                recipientList = EmailRecipients.Split(new char[] { ';' }).ToList();
            }

            return(recipientList);
        }
コード例 #2
0
        /// <summary>
        /// Email the Log file on file rolled
        /// </summary>
        /// <param name="filePath"></param>
        protected override void OnFileRolled(string filePath)
        {
            if (!File.Exists(filePath))
            {
                return;
            }

            try
            {
                int totalErrors   = File.ReadAllLines(filePath).Count(line => Regex.IsMatch(line, ERROR_REGEX));
                int totalWarnings = File.ReadAllLines(filePath).Count(line => Regex.IsMatch(line, WARNING_REGEX));

                string environment = ApplicationSettingsHelper.LoadAppSetting("environment", false, string.Empty);
                if (!string.IsNullOrEmpty(environment))
                {
                    environment = "[{0}]".fmt(environment);
                }

                var info = new SysInfo();
                using (Emailer mailer = Kernel.Get <Emailer>())
                {
                    mailer.AddRecipient(EmailRecipients.Split(';', ','));
                    mailer.AttachFile(filePath);
                    mailer.Send(
                        "[{0} - {1}] {2} {3}"
                        .fmt(EmailSubject,
                             totalErrors != 0 ? "Error" : (totalWarnings != 0 ? "Warning" : "Information"),
                             environment,
                             DateTime.Now.ToString("dd/MM/yyyy")),
                        "{0}\r\n\r\nLog file attached".fmt(info.GetRamDiskUsage()));
                }
            }
            catch (Exception e)
            {
                Logger.WriteUnexpectedException(e, "Failed to email rolled file.", Category.GeneralError);
            }
        }