Skip to content

Commit

Permalink
Merge pull request #24 from Cysharp/hotfix/RemoveLoggerFilter
Browse files Browse the repository at this point in the history
Remove the logger filter registration.
  • Loading branch information
neuecc authored Oct 25, 2019
2 parents f9a778b + 19e2a76 commit d3f2efc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 21 deletions.
15 changes: 0 additions & 15 deletions src/MicroBatchFramework/BatchHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
});
}
}
Expand Down
21 changes: 15 additions & 6 deletions src/MicroBatchFramework/SimpleConsoleLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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>(TState state)
Expand All @@ -37,15 +45,16 @@ public IDisposable BeginScope<TState>(TState state)

public bool IsEnabled(LogLevel logLevel)
{
return true;
return minimumLogLevel <= logLevel;
}

public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> 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))
{
Expand Down

0 comments on commit d3f2efc

Please sign in to comment.