void SendLogEntry(WmiTraceListener listener,
                          LogEntry logEntry)
        {
            ManagementScope scope = new ManagementScope(@"\\." + wmiPath);
            scope.Options.EnablePrivileges = true;

            StringBuilder sb = new StringBuilder("SELECT * FROM ");
            sb.Append("LogEntryV20");
            string query = sb.ToString();
            EventQuery eq = new EventQuery(query);

            using (ManagementEventWatcher watcher = new ManagementEventWatcher(scope, eq))
            {
                watcher.EventArrived += new EventArrivedEventHandler(watcher_EventArrived);
                watcher.Start();

                LogSource source = new LogSource("notfromconfig", SourceLevels.All);
                source.Listeners.Add(listener);
                source.TraceData(TraceEventType.Error, 1, logEntry);

                BlockUntilWMIEventArrives();

                watcher.Stop();
            }
        }
Ejemplo n.º 2
0
        private void SendLogEntry(WmiTraceListener listener, LogEntry logEntry)
        {
            ManagementScope scope = new ManagementScope(@"\\." + this.wmiPath);

            scope.Options.EnablePrivileges = true;

            StringBuilder sb = new StringBuilder("SELECT * FROM ");

            sb.Append("LogEntryV20");
            string     query = sb.ToString();
            EventQuery eq    = new EventQuery(query);

            using (ManagementEventWatcher watcher = new ManagementEventWatcher(scope, eq))
            {
                watcher.EventArrived += new EventArrivedEventHandler(watcher_EventArrived);
                watcher.Start();

                LogSource source = new LogSource("notfromconfig", SourceLevels.All);
                source.Listeners.Add(listener);
                source.TraceData(TraceEventType.Error, 1, logEntry);

                BlockUntilWMIEventArrives();

                watcher.Stop();
            }
        }
        public void TestWMIEventOccurred()
        {
            WmiTraceListener listener = new WmiTraceListener();
            LogEntry         logEntry = new LogEntry("message", "cat1", 0, 0, TraceEventType.Error, "title", null);

            SendLogEntry(listener, logEntry);
            Assert.IsTrue(wmiLogged);
            Assert.IsTrue(wmiResult.IndexOf("message") > -1);
        }
        public void TestLoggingACustomLogEntry()
        {
            WmiTraceListener listener = new WmiTraceListener();
            MyCustomLogEntry logEntry = new MyCustomLogEntry();

            logEntry.MyName = "Enterprise Library Tester";
            SendLogEntry(listener, logEntry);
            Assert.IsTrue(wmiLogged);
            Assert.AreEqual(wmiLogEntry.GetPropertyValue("MyName"), logEntry.MyName);
        }
        public void TestCanGetcategoriesStringsWithWMI()
        {
            WmiTraceListener listener = new WmiTraceListener();
            LogEntry         logEntry = new LogEntry("message", new string[] { "cat1", "cat2", "cat3" }, 0, 0, TraceEventType.Error, "title", null);

            SendLogEntry(listener, logEntry);
            Assert.IsTrue(wmiLogged);
            string[] categoriesStrings = (string[])wmiLogEntry.GetPropertyValue("CategoriesStrings");
            Assert.AreEqual(categoriesStrings.Length, logEntry.Categories.Count);
        }
        public void TestWMIEventWasFiltered()
        {
            WmiTraceListener listener = new WmiTraceListener();

            listener.Filter = new EventTypeFilter(SourceLevels.Off);
            LogEntry logEntry = new LogEntry("message", "cat1", 0, 0, TraceEventType.Error, "title", null);

            SendLogEntry(listener, logEntry);
            Assert.IsFalse(wmiLogged);
            Assert.IsFalse(wmiResult.IndexOf("message") > -1);
        }
        public void TestCanGetActivityIdStringWithWMI()
        {
            WmiTraceListener listener     = new WmiTraceListener();
            LogEntry         logEntry     = new LogEntry("message", "cat1", 0, 0, TraceEventType.Error, "title", null);
            Guid             logEntryGuid = Guid.NewGuid();

            logEntry.ActivityId = logEntryGuid;
            SendLogEntry(listener, logEntry);
            Assert.IsTrue(wmiLogged);
            Assert.AreEqual(wmiLogEntry.GetPropertyValue("ActivityIdString"), logEntryGuid.ToString());
        }
Ejemplo n.º 8
0
        public void TestCanGetActivityIdStringWithWMI()
        {
            WmiTraceListener listener = new WmiTraceListener();

            LogEntry logEntry = new LogEntry("message", "cat1", 0, 0, TraceEventType.Error, "title", null);
            Guid logEntryGuid = Guid.NewGuid();
            logEntry.ActivityId = logEntryGuid;
            SendLogEntry(listener, logEntry);

            Assert.IsTrue(this.wmiLogged);
            Assert.AreEqual(this.wmiLogEntry.GetPropertyValue("ActivityIdString"), logEntryGuid.ToString());
        }
        public void CanCreatePoliciesForWmiTraceListener()
        {
            WmiTraceListenerData listenerData = new WmiTraceListenerData("listener");

            listenerData.TraceOutputOptions = TraceOptions.Callstack | TraceOptions.ProcessId;
            listenerData.Filter             = SourceLevels.Error;
            loggingSettings.TraceListeners.Add(listenerData);

            container.AddExtension(new LoggingBlockExtension());

            WmiTraceListener createdObject = (WmiTraceListener)container.Resolve <TraceListener>("listener");

            Assert.IsNotNull(createdObject);
            Assert.AreEqual(listenerData.TraceOutputOptions, createdObject.TraceOutputOptions);
            Assert.IsNotNull(createdObject.Filter);
            Assert.IsInstanceOfType(createdObject.Filter, typeof(EventTypeFilter));
            Assert.AreEqual(listenerData.Filter, ((EventTypeFilter)createdObject.Filter).EventType);
        }
Ejemplo n.º 10
0
        public void AttributeLookupWillNotHaveAnEffect()
        {
            WmiTraceListener listener = new WmiTraceListener();

            listener.Attributes.Add("formatter", "nonexistent");
        }
Ejemplo n.º 11
0
        public void TestCanGetcategoriesStringsWithWMI()
        {
            WmiTraceListener listener = new WmiTraceListener();

            LogEntry logEntry = new LogEntry("message", new string[] { "cat1", "cat2", "cat3" }, 0, 0, TraceEventType.Error, "title", null);
            SendLogEntry(listener, logEntry);

            Assert.IsTrue(this.wmiLogged);
            string[] categoriesStrings = (string[])this.wmiLogEntry.GetPropertyValue("CategoriesStrings");
            Assert.AreEqual(categoriesStrings.Length, logEntry.Categories.Count);
        }
Ejemplo n.º 12
0
 public void AttributeLookupWillNotHaveAnEffect()
 {
     WmiTraceListener listener = new WmiTraceListener();
      listener.Attributes.Add("formatter", "nonexistent");
 }
Ejemplo n.º 13
0
        public void TestWMIEventOccurred()
        {
            WmiTraceListener listener = new WmiTraceListener();

            LogEntry logEntry = new LogEntry("message", "cat1", 0, 0, TraceEventType.Error, "title", null);
            SendLogEntry(listener, logEntry);

            Assert.IsTrue(this.wmiLogged);
            Assert.IsTrue(this.wmiResult.IndexOf("message") > -1);
        }
Ejemplo n.º 14
0
        public void TestLoggingACustomLogEntry()
        {
            WmiTraceListener listener = new WmiTraceListener();

            MyCustomLogEntry logEntry = new MyCustomLogEntry();
            logEntry.MyName = "Enterprise Library Tester";
            SendLogEntry(listener, logEntry);

            Assert.IsTrue(this.wmiLogged);
            Assert.AreEqual(this.wmiLogEntry.GetPropertyValue("MyName"), logEntry.MyName);
        }
        public void TestWMIEventWasFiltered()
        {
            WmiTraceListener listener = new WmiTraceListener();
            listener.Filter = new EventTypeFilter(SourceLevels.Off);

            LogEntry logEntry = new LogEntry("message", "cat1", 0, 0, TraceEventType.Error, "title", null);
            SendLogEntry(listener, logEntry);

            Assert.IsFalse(wmiLogged);
            Assert.IsFalse(wmiResult.IndexOf("message") > -1);
        }