Esempio n. 1
0
        public void WmiFiredWhenDeliveryToErrorSourceFails()
        {
            TraceListener badTraceListener = new BadTraceListener(new Exception("test exception"));
            LogSource badSource = new LogSource("badSource");
            badSource.Listeners.Add(badTraceListener);

            Dictionary<string, LogSource> logSources = new Dictionary<string,LogSource>();
            logSources.Add("foo", badSource);

            LogWriter writer = new LogWriter(new List<ILogFilter>(), logSources, badSource, "foo");
            new ReflectionInstrumentationBinder().Bind(writer.GetInstrumentationEventProvider(), new LoggingInstrumentationListener(false, false, true));

            using (WmiEventWatcher eventListener = new WmiEventWatcher(1))
            {
                writer.Write(CommonUtil.GetDefaultLogEntry());

                eventListener.WaitForEvents();

                Assert.AreEqual(1, eventListener.EventsReceived.Count);
                Assert.AreEqual("LoggingFailureLoggingErrorEvent", eventListener.EventsReceived[0].ClassPath.ClassName);
                string exceptionMessage = (string) eventListener.EventsReceived[0].GetPropertyValue("ExceptionMessage");
                Assert.IsTrue(-1 != exceptionMessage.IndexOf("test exception"));
                Assert.IsNotNull(eventListener.EventsReceived[0].GetPropertyValue("ErrorMessage"));
            }
        }
Esempio n. 2
0
        public void EventLogWrittenWhenDeliveryToErrorSourceFails()
        {
            TraceListener badTraceListener = new BadTraceListener(new Exception("test exception"));
            LogSource badSource = new LogSource("badSource");
            badSource.Listeners.Add(badTraceListener);

            Dictionary<string, LogSource> logSources = new Dictionary<string, LogSource>();
            logSources.Add("foo", badSource);

            LogWriter writer = new LogWriter(new List<ILogFilter>(), logSources, badSource, "foo");
            new ReflectionInstrumentationBinder().Bind(writer.GetInstrumentationEventProvider(), new LoggingInstrumentationListener(false, true, false));

            writer.Write(CommonUtil.GetDefaultLogEntry());

            string lastEventLogEntry = CommonUtil.GetLastEventLogEntry();
            Assert.IsTrue(-1 != lastEventLogEntry.IndexOf("test exception"));
        }