public void JsonFormatterHeadersAreSetWhenSendingEmail()
        {
            DateTime messageTimestamp = DateTime.UtcNow;

            LoggingConfiguration loggingConfiguration = BuildProgrammaticConfigForTrace();

            JsonLogFormatter jsonformatter = new JsonLogFormatter(JsonFormatting.Indented);

            EmailTraceListener emailListener = new EmailTraceListener(this.toaddress,
                                                                      this.fromaddress,
                                                                      "StartOfSubject",
                                                                      "EndOfSubject", this.smtpserver, jsonformatter);

            emailListener.Filter = new EventTypeFilter(SourceLevels.All);
            loggingConfiguration.AddLogSource("Email", SourceLevels.All, true, emailListener);
            loggingConfiguration.SpecialSources.Unprocessed.Listeners.Add(emailListener);

            string message = "Test JSON";

            this.writer = new LogWriter(loggingConfiguration);
            this.writer.Write(message, "General");
            this.writer.Dispose();

            string emailText   = LogFileReader.GetEmail();
            string endOfHeader = "\r\n\r\n";
            int    index       = emailText.IndexOf(endOfHeader);
            string header      = emailText.Substring(0, index);

            Dictionary <string, string> emailDictionary = Regex.Split(header, "\r\n").Select(e => e.Split(':')).ToDictionary(line => line[0], line => line[1].Trim());

            Assert.AreEqual("StartOfSubject Information EndOfSubject", emailDictionary["Subject"]);
            Assert.AreEqual(this.fromaddress, emailDictionary["From"]);
            Assert.AreEqual(this.toaddress, emailDictionary["To"]);
        }
        public void EmailIsSent()
        {
            LogWriterFactory factory = new LogWriterFactory((e) => this.ConfigurationSource.GetSection("loggingConfiguration100"));

            factory.Create().Write("Test", "General");

            Assert.IsNotNull(LogFileReader.GetEmail());
        }
        public void EmailIsSentWhenGeneralCategoryNoEmailAuth()
        {
            LoggingConfiguration loggingConfiguration = BuildProgrammaticConfigForTrace();

            this.UpdateConfigForEmailNoEmailAuth(loggingConfiguration);

            this.writer = new LogWriter(loggingConfiguration);
            this.writer.Write("Test Log Entry in Email - EmailGeneralCategoryNoEmailAuth", "General",
                              5, 9008, TraceEventType.Warning, "Logging Block EmailProgConfig Sample");
            string emailContent = LogFileReader.GetEmail();

            Assert.IsTrue(emailContent.Contains(string.Format("\r\nTo: {0}\r\n", this.toaddress)));
        }
        public void EmailIsNotSentWhenLogEnabledFilterIsFalse()
        {
            LoggingConfiguration loggingConfiguration = BuildProgrammaticConfigForTrace();

            this.UpdateConfigForEmailNoPortEmailAuth(loggingConfiguration);

            var logEnabledFilter = new LogEnabledFilter("LogEnabled Filter", false);

            loggingConfiguration.Filters.Add(logEnabledFilter);

            this.writer = new LogWriter(loggingConfiguration);
            this.writer.Write("Test Logging Not Present");
            this.writer.Dispose();

            string emailContent = LogFileReader.GetEmail();

            Assert.IsNull(emailContent);
        }
        public void EmailIsSentWhenCategoriesSeverityVerbose()
        {
            LogFileReader.CreateDirectory("mail");

            LogWriterFactory factory = new LogWriterFactory((e) => this.ConfigurationSource.GetSection("loggingConfiguration75"));

            this.writer = factory.Create();
            Logger.SetLogWriter(this.writer);

            LogEntry entry = new LogEntry();

            entry.Categories.Add("General");
            entry.Message  = "Email Message Test";
            entry.EventId  = 123;
            entry.Priority = 11;
            entry.Severity = TraceEventType.Error;

            this.writer.Write(entry);

            Assert.IsNotNull(LogFileReader.GetEmail());
        }