diff --git a/src/MicroBatchFramework/BatchHost.cs b/src/MicroBatchFramework/BatchHost.cs index e9228b7..67a29fb 100644 --- a/src/MicroBatchFramework/BatchHost.cs +++ b/src/MicroBatchFramework/BatchHost.cs @@ -100,21 +100,6 @@ internal static void ConfigureLoggingDefault(IHostBuilder builder, bool useSimpl } logging.AddSimpleConsole(); - logging.AddFilter((providerName, category, level) => - { - if (providerName == typeof(SimpleConsoleLogger).FullName) - { - // omit system message - if (category.StartsWith("Microsoft.Extensions.Hosting.Internal")) - { - if (level <= LogLevel.Debug) return false; - } - - return level >= minSimpleConsoleLoggerLogLevel; - } - - return true; - }); }); } } diff --git a/src/MicroBatchFramework/SimpleConsoleLogger.cs b/src/MicroBatchFramework/SimpleConsoleLogger.cs index 03bb67f..f9dfc3c 100644 --- a/src/MicroBatchFramework/SimpleConsoleLogger.cs +++ b/src/MicroBatchFramework/SimpleConsoleLogger.cs @@ -7,16 +7,21 @@ namespace MicroBatchFramework.Logging { public class SimpleConsoleLoggerProvider : ILoggerProvider { - readonly SimpleConsoleLogger logger; + readonly SimpleConsoleLogger loggerDefault; + readonly SimpleConsoleLogger loggerHostingInternal; public SimpleConsoleLoggerProvider() { - logger = new SimpleConsoleLogger(); + loggerDefault = new SimpleConsoleLogger(LogLevel.Trace); + loggerHostingInternal = new SimpleConsoleLogger(LogLevel.Information); } public ILogger CreateLogger(string categoryName) { - return logger; + // NOTE: It omits unimportant log messages from Microsoft.Extension.Hosting.Internal.* + return categoryName.StartsWith("Microsoft.Extensions.Hosting.Internal") + ? loggerHostingInternal + : loggerDefault; } public void Dispose() @@ -26,8 +31,11 @@ public void Dispose() public class SimpleConsoleLogger : ILogger { - public SimpleConsoleLogger() + readonly LogLevel minimumLogLevel; + + public SimpleConsoleLogger(LogLevel minimumLogLevel) { + this.minimumLogLevel = minimumLogLevel; } public IDisposable BeginScope(TState state) @@ -37,15 +45,16 @@ public IDisposable BeginScope(TState state) public bool IsEnabled(LogLevel logLevel) { - return true; + return minimumLogLevel <= logLevel; } public void Log(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func formatter) { if (formatter == null) throw new ArgumentNullException(nameof(formatter)); - var msg = formatter(state, exception); + if (minimumLogLevel > logLevel) return; + var msg = formatter(state, exception); if (!string.IsNullOrEmpty(msg)) {