diff --git a/src/DataCollectors/Microsoft.TestPlatform.Extensions.EventLogCollector/EventLogDataCollector.cs b/src/DataCollectors/Microsoft.TestPlatform.Extensions.EventLogCollector/EventLogDataCollector.cs index 505d72f732..fdad5edbbb 100644 --- a/src/DataCollectors/Microsoft.TestPlatform.Extensions.EventLogCollector/EventLogDataCollector.cs +++ b/src/DataCollectors/Microsoft.TestPlatform.Extensions.EventLogCollector/EventLogDataCollector.cs @@ -575,7 +575,7 @@ private void ConfigureEventLogNames(CollectorNameValueConfigurationManager colle catch (Exception ex) { this.logger.LogError( - null, + this.dataCollectorContext, new EventLogCollectorException(string.Format(CultureInfo.InvariantCulture, Resource.ReadError, eventLogName, Environment.MachineName), ex)); } } diff --git a/test/DataCollectors/Microsoft.TestPlatform.Extensions.EventLogCollector.UnitTests/EventLogDataCollectorTests.cs b/test/DataCollectors/Microsoft.TestPlatform.Extensions.EventLogCollector.UnitTests/EventLogDataCollectorTests.cs index 9129857986..d541a0d6d3 100644 --- a/test/DataCollectors/Microsoft.TestPlatform.Extensions.EventLogCollector.UnitTests/EventLogDataCollectorTests.cs +++ b/test/DataCollectors/Microsoft.TestPlatform.Extensions.EventLogCollector.UnitTests/EventLogDataCollectorTests.cs @@ -48,6 +48,22 @@ public EventLogDataCollectorTests() this.eventLogDataCollector = new EventLogDataCollector(this.mockFileHelper.Object); } + [TestMethod] + public void EventLoggerLogsErrorForInvalidEventSources() + { + string configurationString = + @""; + XmlDocument expectedXmlDoc = new XmlDocument(); + expectedXmlDoc.LoadXml(configurationString); + var mockCollector = new Mock(); + mockCollector.Setup(m => m.LogError(It.IsAny(), It.Is(s => s.Contains(@"The event log 'MyEventName' on computer '.' does not exist.")), It.IsAny())); + + var eventLogDataCollector = new EventLogDataCollector(); + eventLogDataCollector.Initialize(expectedXmlDoc.DocumentElement, this.mockDataCollectionEvents.Object, this.mockDataCollectionSink, mockCollector.Object, this.dataCollectionEnvironmentContext); + + mockCollector.Verify(m => m.LogError(It.IsAny(), It.IsAny(), It.IsAny()), Times.Once); + } + [TestMethod] public void InitializeShouldThrowExceptionIfEventsIsNull() {