Example #1
0
        public void WriteDictionary()
        {
            try
            {
                if (!EventLog.SourceExists("Unit Test"))
                {
                    Assert.Inconclusive("Source named 'Unit Test' does not exist.");
                }
            }
            catch (SecurityException ex)
            {
                Assert.Inconclusive("In order to run the tests, please run Visual Studio as Administrator.\r\n{0}", ex.ToString());
            }

            LogEntry entry = CommonUtil.GetDefaultLogEntry();

            entry.Categories         = new string[] { "DictionaryCategory" };
            entry.Severity           = TraceEventType.Error;
            entry.ExtendedProperties = CommonUtil.GetPropertiesDictionary();

            Logger.Write(entry);

            string expected = CommonUtil.FormattedMessageWithDictionary;
            string actual   = CommonUtil.GetLastEventLogEntryCustom();

            Assert.IsTrue(actual.IndexOf("key1") > -1);
            Assert.IsTrue(actual.IndexOf("value1") > -1);
            Assert.IsTrue(actual.IndexOf("key2") > -1);
            Assert.IsTrue(actual.IndexOf("value2") > -1);
            Assert.IsTrue(actual.IndexOf("key3") > -1);
            Assert.IsTrue(actual.IndexOf("value3") > -1);
        }
        public void WriteDictionary()
        {
            if (!EventLog.SourceExists("Unit Test"))
            {
                return;
            }

            LogEntry entry = CommonUtil.GetDefaultLogEntry();

            entry.Categories         = new string[] { "DictionaryCategory" };
            entry.Severity           = TraceEventType.Error;
            entry.ExtendedProperties = CommonUtil.GetPropertiesDictionary();

            Logger.Write(entry);

            string expected = CommonUtil.FormattedMessageWithDictionary;
            string actual   = CommonUtil.GetLastEventLogEntryCustom();

            Assert.IsTrue(actual.IndexOf("key1") > -1);
            Assert.IsTrue(actual.IndexOf("value1") > -1);
            Assert.IsTrue(actual.IndexOf("key2") > -1);
            Assert.IsTrue(actual.IndexOf("value2") > -1);
            Assert.IsTrue(actual.IndexOf("key3") > -1);
            Assert.IsTrue(actual.IndexOf("value3") > -1);
        }
Example #3
0
        public void WriteDictionary()
        {
            SetInProcDistributionStrategy();
            LogEntry entry = CommonUtil.GetDefaultLogEntry();

            entry.Category           = "DictionaryCategory";
            entry.ExtendedProperties = CommonUtil.GetPropertiesHashtable();

            Logger.Write(entry);

            string expected = CommonUtil.FormattedMessageWithDictionary;
            string actual   = CommonUtil.GetLastEventLogEntryCustom();

            Assert.AreEqual(expected, actual);
        }
        public void SendToFormattedCategory()
        {
            SetInProcDistributionStrategy();

            CustomLogEntry customLog = GetCustomLogEntry();

            customLog.Category = "FormattedCategory";
            Logger.Write(customLog);

            string expected = customLog.TimeStamp +
                              ": " + customLog.Title +
                              "\r\n\r\n" + customLog.Message;
            string entry = CommonUtil.GetLastEventLogEntryCustom();

            Assert.IsTrue(entry.IndexOf(expected) > -1);
        }
        public void SendToEventLog()
        {
            SetInProcDistributionStrategy();

            CustomLogEntry customLog = GetCustomLogEntry();

            customLog.Category    = "AppTest";
            customLog.TimeStamp   = DateTime.MaxValue;
            customLog.MachineName = "machine";
            Logger.Write(customLog);

            string expected = "<EntLibLog>\r\n\t<message>My message body</message>\r\n\t<timestamp>12/31/9999 11:59:59 PM</timestamp>\r\n\t<title>My Custom Log Entry Title</title>\r\n</EntLibLog>";
            string entry    = CommonUtil.GetLastEventLogEntryCustom();

            Assert.AreEqual(expected, entry);
        }
        public void CustomTextFormatter()
        {
            SetInProcDistributionStrategy();

            CustomLogEntry customEntry = GetCustomLogEntry();

            customEntry.Category = "CustomFormattedCategory";

            Logger.Write(customEntry);

            string expected = "Timestamp: " + customEntry.TimeStampString +
                              "\r\nTitle: My Custom Log Entry Title\r\n\r\nAcme Field1: Red\r\nAcme Field2: Blue\r\nAcme Field3: Green\r\n\r\nMessage: My message body";

            string entry = CommonUtil.GetLastEventLogEntryCustom();

            Assert.IsTrue(entry.IndexOf(expected) > -1);
        }
Example #7
0
        public void WriteEntryWithMessages()
        {
            SetInProcDistributionStrategy();
            LogEntry log = new LogEntry();

            log.Category = "AppTest";
            log.Message  = "My Body";
            log.Title    = "My Header";
            log.EventId  = 25;
            log.Severity = Severity.Warning;
            log.Priority = loggingSettings.MinimumPriority;
            log.AddErrorMessage("hey");
            log.AddErrorMessage("yes");

            Logger.Write(log);

            string actual   = CommonUtil.GetLastEventLogEntryCustom();
            string expected = "yes\r\n\r\nhey";
            int    pos      = actual.IndexOf(expected);

            Assert.IsTrue(pos > -1);
        }