Fix EventLogsPipeline to throw PipelineException when LoggingSourceConfiguration...
authorJustin Anderson <jander-msft@users.noreply.github.com>
Tue, 18 May 2021 01:48:20 +0000 (18:48 -0700)
committerGitHub <noreply@github.com>
Tue, 18 May 2021 01:48:20 +0000 (18:48 -0700)
src/Microsoft.Diagnostics.Monitoring.EventPipe/Logs/EventLogsPipeline.cs
src/tests/Microsoft.Diagnostics.Monitoring.EventPipe/EventLogsPipelineUnitTests.cs

index 31db6a531ba914fb3d30d9d3a134c1ead7b48ef6..7f512203fbc37868ad8a9f5dc539beb527dac68e 100644 (file)
@@ -25,11 +25,18 @@ namespace Microsoft.Diagnostics.Monitoring.EventPipe
 
         protected override MonitoringSourceConfiguration CreateConfiguration()
         {
-            return new LoggingSourceConfiguration(
-                Settings.LogLevel,
-                LogMessageType.FormattedMessage | LogMessageType.JsonMessage,
-                Settings.FilterSpecs,
-                Settings.UseAppFilters);
+            try
+            {
+                return new LoggingSourceConfiguration(
+                    Settings.LogLevel,
+                    LogMessageType.FormattedMessage | LogMessageType.JsonMessage,
+                    Settings.FilterSpecs,
+                    Settings.UseAppFilters);
+            }
+            catch (NotSupportedException ex)
+            {
+                throw new PipelineException(ex.Message, ex);
+            }
         }
 
         protected override Task OnEventSourceAvailable(EventPipeEventSource eventSource, Func<Task> stopSessionAsync, CancellationToken token)
index f9eb43ab1f65db1fdab7dad920c31a412a99dc9f..b493d4d47a570be0c7af54482e80fe83cd7fe06a 100644 (file)
@@ -108,13 +108,18 @@ namespace Microsoft.Diagnostics.Monitoring.EventPipe.UnitTests
         /// Test that LogLevel.None is not supported as the default log level.
         /// </summary>
         [Fact]
-        public Task TestLogsAllCategoriesDefaultLevelNoneNotSupported()
+        public async Task TestLogsAllCategoriesDefaultLevelNoneNotSupported()
         {
-            return Assert.ThrowsAsync<NotSupportedException>(() => GetLogsAsync(settings =>
-            {
-                settings.UseAppFilters = false;
-                settings.LogLevel = LogLevel.None;
-            }));
+            // Pipeline should throw PipelineException with inner exception of NotSupportedException.
+            PipelineException exception = await Assert.ThrowsAsync<PipelineException>(
+                () => GetLogsAsync(
+                    settings =>
+                    {
+                        settings.UseAppFilters = false;
+                        settings.LogLevel = LogLevel.None;
+                    }));
+
+            Assert.IsType<NotSupportedException>(exception.InnerException);
         }
 
         /// <summary>