// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+using System;
using System.Collections.Generic;
using System.Diagnostics.Tracing;
using Microsoft.Diagnostics.NETCore.Client;
{
public class LoggingSourceConfiguration : MonitoringSourceConfiguration
{
+ private const string UseAppFilters = "UseAppFilters";
+
private readonly LogLevel _level;
+ private readonly bool _useAppFilters;
- public LoggingSourceConfiguration(LogLevel level = LogLevel.Debug)
+ /// <summary>
+ /// Creates a new logging source configuration.
+ /// </summary>
+ /// <param name="level">The logging level. Log messages at or above the log level will be included.</param>
+ /// <param name="useAppFilters">Use the UseAppFilters filterspec. This supersedes the log level and generates
+ /// log messages with the same levels per category as specified by the application configuration.</param>
+ public LoggingSourceConfiguration(LogLevel level = LogLevel.Debug, bool useAppFilters = false)
{
_level = level;
+ _useAppFilters = useAppFilters;
}
public override IList<EventPipeProvider> GetProviders()
{
+ string filterSpec = _useAppFilters ? UseAppFilters : FormattableString.Invariant($"*:{_level:G}");
+
var providers = new List<EventPipeProvider>()
{
+
// Logging
new EventPipeProvider(
MicrosoftExtensionsLoggingProviderName,
(long)(LoggingEventSource.Keywords.JsonMessage | LoggingEventSource.Keywords.FormattedMessage),
arguments: new Dictionary<string,string>
{
- // Filter all loggers to the specified level
- { "FilterSpecs", $"*:{_level:G}" }
+
+ { "FilterSpecs", filterSpec }
}
)
};
protected override MonitoringSourceConfiguration CreateConfiguration()
{
- return new LoggingSourceConfiguration(Settings.LogLevel);
+ return new LoggingSourceConfiguration(Settings.LogLevel, Settings.UseAppFilters);
}
protected override Task OnEventSourceAvailable(EventPipeEventSource eventSource, Func<Task> stopSessionAsync, CancellationToken token)