Example #1
0
        public void FormatCustomTokenFunction()
        {
            CustomLogEntry entry = new CustomLogEntry();

            CustomTextFormatterData data = new CustomTextFormatterData();
            data.Template.Value = "Acme custom token template: [[AcmeDBLookup{value1}]]";

            ILogFormatter formatter = new CustomTextFormatter(data);
            string actual = formatter.Format(entry);

            string expected = "Acme custom token template: 1234";
            Assert.AreEqual(expected, actual);
        }
        public void SendToCustomLogEntrySink()
        {
            SetInProcDistributionStrategy();

            CustomLogEntry customLog = GetCustomLogEntry();

            customLog.Category = "CustomMessageCategory";

            Logger.Write(customLog);

            Assert.AreEqual(customLog.AcmeCoField1, CustomLogEntrySink.Field1);
            Assert.AreEqual(customLog.AcmeCoField2, CustomLogEntrySink.Field2);
            Assert.AreEqual(customLog.AcmeCoField3, CustomLogEntrySink.Field3);
        }
        public void SendToMockDistributionStrategy()
        {
            SetMockDistributionStrategy();
            CustomLogEntry customLog = GetCustomLogEntry();

            Logger.Write(customLog);

            CustomLogEntry mockEntry = (CustomLogEntry)MockDistributionStrategy.Entry;

            Assert.AreEqual(customLog.AcmeCoField1, mockEntry.AcmeCoField1);
            Assert.AreEqual(customLog.AcmeCoField2, mockEntry.AcmeCoField2);
            Assert.AreEqual(customLog.AcmeCoField3, mockEntry.AcmeCoField3);
            Assert.AreEqual(customLog.Category, mockEntry.Category);
            Assert.AreEqual(customLog.Message, mockEntry.Message);
        }
        public void SendToCustomLogEntrySinkAndMockSink()
        {
            SetInProcDistributionStrategy();

            CustomLogEntry customEntry = GetCustomLogEntry();

            customEntry.Category = "MixedCategory";

            Logger.Write(customEntry);

            Assert.AreEqual(CustomLogEntrySink.fullMessage, MockLogSink.FormatLogEntry(MockLogSink.GetLastEntry()));
            Assert.AreEqual(CustomLogEntrySink.Body, MockLogSink.GetLastEntry().Message);
            Assert.AreEqual(CustomLogEntrySink.EventID, MockLogSink.GetLastEntry().EventId);
            Assert.AreEqual(CustomLogEntrySink.Category, MockLogSink.GetLastEntry().Category);
        }
        private CustomLogEntry GetCustomLogEntry()
        {
            CustomLogEntry customLog = new CustomLogEntry();

            customLog.Category     = "MockCategoryOne";
            customLog.EventId      = CommonUtil.MsgEventID;
            customLog.Message      = CommonUtil.MsgBody;
            customLog.Title        = "My Custom Log Entry Title";
            customLog.AcmeCoField1 = "Red";
            customLog.AcmeCoField2 = "Blue";
            customLog.AcmeCoField3 = "Green";
            customLog.TimeStamp    = DateTime.MaxValue;

            return(customLog);
        }
        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 SendToMockSink()
        {
            SetInProcDistributionStrategy();

            CustomLogEntry customLog = GetCustomLogEntry();

            Logger.Write(customLog);

            CustomLogEntry deserializedLog = (CustomLogEntry)MockLogSink.GetLastEntry();

            Assert.AreEqual(customLog.AcmeCoField1, deserializedLog.AcmeCoField1);
            Assert.AreEqual(customLog.AcmeCoField2, deserializedLog.AcmeCoField2);
            Assert.AreEqual(customLog.AcmeCoField3, deserializedLog.AcmeCoField3);
            Assert.AreEqual(customLog.Category, deserializedLog.Category);
            Assert.AreEqual(customLog.Message, deserializedLog.Message);
        }
        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 #10
0
        private CustomLogEntry GetCustomLogEntry()
        {
            CustomLogEntry customLog = new CustomLogEntry();
            customLog.Category = "MockCategoryOne";
            customLog.EventId = CommonUtil.MsgEventID;
            customLog.Message = CommonUtil.MsgBody;
            customLog.Title = "My Custom Log Entry Title";
            customLog.AcmeCoField1 = "Red";
            customLog.AcmeCoField2 = "Blue";
            customLog.AcmeCoField3 = "Green";
            customLog.TimeStamp = DateTime.MaxValue;

            return customLog;
        }
        public void SendCustomLogEntryViaMsmq()
        {
            CustomLogEntry log = new CustomLogEntry();
            log.TimeStamp = DateTime.MaxValue;
            log.Title = "My custom message title";
            log.Message = "My custom message body";
            log.Categories = new string[] { "CustomFormattedCategory" };
            log.AcmeCoField1 = "apple";
            log.AcmeCoField2 = "orange";
            log.AcmeCoField3 = "lemon";

            clientSource.TraceData(TraceEventType.Information, 1, log);

            msmqDistributor.CheckForMessages();

            //string expected = "Timestamp: 12/31/9999 11:59:59 PM\r\nTitle: My custom message title\r\n\r\nAcme Field1: apple\r\nAcme Field2: orange\r\nAcme Field3: lemon\r\n\r\nMessage: My custom message body";
            Assert.IsFalse(MockTraceListener.LastEntry == log);
            Assert.AreEqual(MockTraceListener.LastEntry.Message, log.Message);
            Assert.AreEqual(((CustomLogEntry)MockTraceListener.LastEntry).AcmeCoField1, log.AcmeCoField1);
            Assert.AreEqual(((CustomLogEntry)MockTraceListener.LastEntry).AcmeCoField2, log.AcmeCoField2);
            Assert.AreEqual(((CustomLogEntry)MockTraceListener.LastEntry).AcmeCoField3, log.AcmeCoField3);
        }
        public void SendCustomLogEntryViaMsmq()
        {
            CustomLogEntry log = new CustomLogEntry();
            log.TimeStamp = DateTime.MaxValue;
            log.Title = "My custom message title";
            log.Message = "My custom message body";
            log.Category = "CustomFormattedCategory";
            log.AcmeCoField1 = "apple";
            log.AcmeCoField2 = "orange";
            log.AcmeCoField3 = "lemon";

            msmq.SendLog(log);

            msmqDistributor.CheckForMessages();

            string expected = "Timestamp: 12/31/9999 11:59:59 PM\r\nTitle: My custom message title\r\n\r\nAcme Field1: apple\r\nAcme Field2: orange\r\nAcme Field3: lemon\r\n\r\nMessage: My custom message body";
            string actual = CommonUtil.GetLastEventLogEntryCustom();
            Assert.AreEqual(expected, actual);
        }