Skip to content

Commit d3f2efc

Browse files
authored
Merge pull request #24 from Cysharp/hotfix/RemoveLoggerFilter
Remove the logger filter registration.
2 parents f9a778b + 19e2a76 commit d3f2efc

File tree

2 files changed

+15
-21
lines changed

2 files changed

+15
-21
lines changed

src/MicroBatchFramework/BatchHost.cs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -100,21 +100,6 @@ internal static void ConfigureLoggingDefault(IHostBuilder builder, bool useSimpl
100100
}
101101

102102
logging.AddSimpleConsole();
103-
logging.AddFilter((providerName, category, level) =>
104-
{
105-
if (providerName == typeof(SimpleConsoleLogger).FullName)
106-
{
107-
// omit system message
108-
if (category.StartsWith("Microsoft.Extensions.Hosting.Internal"))
109-
{
110-
if (level <= LogLevel.Debug) return false;
111-
}
112-
113-
return level >= minSimpleConsoleLoggerLogLevel;
114-
}
115-
116-
return true;
117-
});
118103
});
119104
}
120105
}

src/MicroBatchFramework/SimpleConsoleLogger.cs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,21 @@ namespace MicroBatchFramework.Logging
77
{
88
public class SimpleConsoleLoggerProvider : ILoggerProvider
99
{
10-
readonly SimpleConsoleLogger logger;
10+
readonly SimpleConsoleLogger loggerDefault;
11+
readonly SimpleConsoleLogger loggerHostingInternal;
1112

1213
public SimpleConsoleLoggerProvider()
1314
{
14-
logger = new SimpleConsoleLogger();
15+
loggerDefault = new SimpleConsoleLogger(LogLevel.Trace);
16+
loggerHostingInternal = new SimpleConsoleLogger(LogLevel.Information);
1517
}
1618

1719
public ILogger CreateLogger(string categoryName)
1820
{
19-
return logger;
21+
// NOTE: It omits unimportant log messages from Microsoft.Extension.Hosting.Internal.*
22+
return categoryName.StartsWith("Microsoft.Extensions.Hosting.Internal")
23+
? loggerHostingInternal
24+
: loggerDefault;
2025
}
2126

2227
public void Dispose()
@@ -26,8 +31,11 @@ public void Dispose()
2631

2732
public class SimpleConsoleLogger : ILogger
2833
{
29-
public SimpleConsoleLogger()
34+
readonly LogLevel minimumLogLevel;
35+
36+
public SimpleConsoleLogger(LogLevel minimumLogLevel)
3037
{
38+
this.minimumLogLevel = minimumLogLevel;
3139
}
3240

3341
public IDisposable BeginScope<TState>(TState state)
@@ -37,15 +45,16 @@ public IDisposable BeginScope<TState>(TState state)
3745

3846
public bool IsEnabled(LogLevel logLevel)
3947
{
40-
return true;
48+
return minimumLogLevel <= logLevel;
4149
}
4250

4351
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter)
4452
{
4553
if (formatter == null) throw new ArgumentNullException(nameof(formatter));
4654

47-
var msg = formatter(state, exception);
55+
if (minimumLogLevel > logLevel) return;
4856

57+
var msg = formatter(state, exception);
4958

5059
if (!string.IsNullOrEmpty(msg))
5160
{

0 commit comments

Comments
 (0)