From e7045fb1900b843fc841dd81aee96a88048c2e42 Mon Sep 17 00:00:00 2001 From: Mayuki Sawatari Date: Mon, 15 Apr 2019 17:51:37 +0900 Subject: [PATCH 1/2] Remove SimpleConsoleLogger dependency from BatchEngine initialization. --- sandbox/MultiContainedApp/Program.cs | 3 ++- .../BatchEngineHostBuilderExtensions.cs | 22 +++++-------------- src/MicroBatchFramework/BatchHost.cs | 16 +++++++------- 3 files changed, 16 insertions(+), 25 deletions(-) diff --git a/sandbox/MultiContainedApp/Program.cs b/sandbox/MultiContainedApp/Program.cs index 3f87805..911474d 100644 --- a/sandbox/MultiContainedApp/Program.cs +++ b/sandbox/MultiContainedApp/Program.cs @@ -10,7 +10,8 @@ class Program { static async Task Main(string[] args) { - await BatchHost.CreateDefaultBuilder().RunBatchEngineAsync(args); + await BatchHost.CreateDefaultBuilder(useSimpleConosoleLogger:true) + .RunBatchEngineAsync(args); } } diff --git a/src/MicroBatchFramework/BatchEngineHostBuilderExtensions.cs b/src/MicroBatchFramework/BatchEngineHostBuilderExtensions.cs index c92cbd9..7a7002c 100644 --- a/src/MicroBatchFramework/BatchEngineHostBuilderExtensions.cs +++ b/src/MicroBatchFramework/BatchEngineHostBuilderExtensions.cs @@ -15,7 +15,7 @@ public static class BatchEngineHostBuilderExtensions const string ListCommand = "list"; const string HelpCommand = "help"; - public static IHostBuilder UseBatchEngine(this IHostBuilder hostBuilder, string[] args, IBatchInterceptor interceptor = null, bool useSimpleConosoleLogger = true) + public static IHostBuilder UseBatchEngine(this IHostBuilder hostBuilder, string[] args, IBatchInterceptor interceptor = null) { if (args.Length == 0 || (args.Length == 1 && args[0].Equals(ListCommand, StringComparison.OrdinalIgnoreCase))) { @@ -76,20 +76,15 @@ public static IHostBuilder UseBatchEngine(this IHostBuilder hostBuilder, string[ } }); - if (useSimpleConosoleLogger) - { - hostBuilder = hostBuilder.ConfigureLogging(x => x.AddSimpleConsole()); - } - return hostBuilder.UseConsoleLifetime(); } - public static Task RunBatchEngineAsync(this IHostBuilder hostBuilder, string[] args, IBatchInterceptor interceptor = null, bool useSimpleConosoleLogger = true) + public static Task RunBatchEngineAsync(this IHostBuilder hostBuilder, string[] args, IBatchInterceptor interceptor = null) { - return UseBatchEngine(hostBuilder, args, interceptor, useSimpleConosoleLogger).Build().RunAsync(); + return UseBatchEngine(hostBuilder, args, interceptor).Build().RunAsync(); } - public static IHostBuilder UseBatchEngine(this IHostBuilder hostBuilder, string[] args, IBatchInterceptor interceptor = null, bool useSimpleConosoleLogger = true) + public static IHostBuilder UseBatchEngine(this IHostBuilder hostBuilder, string[] args, IBatchInterceptor interceptor = null) where T : BatchBase { var method = typeof(T).GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly); @@ -151,18 +146,13 @@ public static IHostBuilder UseBatchEngine(this IHostBuilder hostBuilder, stri services.AddTransient(); }); - if (useSimpleConosoleLogger) - { - hostBuilder = hostBuilder.ConfigureLogging(x => x.AddSimpleConsole()); - } - return hostBuilder.UseConsoleLifetime(); } - public static Task RunBatchEngineAsync(this IHostBuilder hostBuilder, string[] args, IBatchInterceptor interceptor = null, bool useSimpleConosoleLogger = true) + public static Task RunBatchEngineAsync(this IHostBuilder hostBuilder, string[] args, IBatchInterceptor interceptor = null) where T : BatchBase { - return UseBatchEngine(hostBuilder, args, interceptor, useSimpleConosoleLogger).Build().RunAsync(); + return UseBatchEngine(hostBuilder, args, interceptor).Build().RunAsync(); } static void ShowMethodList() diff --git a/src/MicroBatchFramework/BatchHost.cs b/src/MicroBatchFramework/BatchHost.cs index 4cbfbbe..d86e53c 100644 --- a/src/MicroBatchFramework/BatchHost.cs +++ b/src/MicroBatchFramework/BatchHost.cs @@ -28,7 +28,7 @@ public static class BatchHost /// and configure the to log to the console, /// /// The initialized . - public static IHostBuilder CreateDefaultBuilder(bool useSimpleConosoleLogger = true) => CreateDefaultBuilder(useSimpleConosoleLogger, LogLevel.Debug); + public static IHostBuilder CreateDefaultBuilder(bool useSimpleConsoleLogger = true) => CreateDefaultBuilder(useSimpleConsoleLogger, LogLevel.Debug); /// /// Initializes a new instance of the class with pre-configured defaults. @@ -41,10 +41,10 @@ public static class BatchHost /// load from environment variables, /// and configure the to log to the console, /// - /// + /// /// /// The initialized . - public static IHostBuilder CreateDefaultBuilder(bool useSimpleConosoleLogger, LogLevel minSimpleConsoleLoggerLogLevel) => CreateDefaultBuilder(useSimpleConosoleLogger, minSimpleConsoleLoggerLogLevel, ""); + public static IHostBuilder CreateDefaultBuilder(bool useSimpleConsoleLogger, LogLevel minSimpleConsoleLoggerLogLevel) => CreateDefaultBuilder(useSimpleConsoleLogger, minSimpleConsoleLoggerLogLevel, ""); /// /// Initializes a new instance of the class with pre-configured defaults. @@ -57,17 +57,17 @@ public static class BatchHost /// load from environment variables, /// and configure the to log to the console, /// - /// + /// /// /// /// The initialized . - public static IHostBuilder CreateDefaultBuilder(bool useSimpleConosoleLogger, LogLevel minSimpleConsoleLoggerLogLevel, string hostEnvironmentVariable) + public static IHostBuilder CreateDefaultBuilder(bool useSimpleConsoleLogger, LogLevel minSimpleConsoleLoggerLogLevel, string hostEnvironmentVariable) { var builder = new HostBuilder(); ConfigureHostConfigurationDefault(builder, hostEnvironmentVariable); ConfigureAppConfigurationDefault(builder); - ConfigureLoggingDefault(builder, useSimpleConosoleLogger, minSimpleConsoleLoggerLogLevel); + ConfigureLoggingDefault(builder, useSimpleConsoleLogger, minSimpleConsoleLoggerLogLevel); return builder; } @@ -111,9 +111,9 @@ internal static void ConfigureAppConfigurationDefault(IHostBuilder builder) }); } - internal static void ConfigureLoggingDefault(IHostBuilder builder, bool useSimpleConosoleLogger, LogLevel minSimpleConsoleLoggerLogLevel) + internal static void ConfigureLoggingDefault(IHostBuilder builder, bool useSimpleConsoleLogger, LogLevel minSimpleConsoleLoggerLogLevel) { - if (useSimpleConosoleLogger) + if (useSimpleConsoleLogger) { builder.ConfigureLogging(logging => { From 256fab5bc733282cd38fbb68de7a99c2adaba8d3 Mon Sep 17 00:00:00 2001 From: Mayuki Sawatari Date: Mon, 15 Apr 2019 18:09:54 +0900 Subject: [PATCH 2/2] Remove unnecessary parameter --- sandbox/MultiContainedApp/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sandbox/MultiContainedApp/Program.cs b/sandbox/MultiContainedApp/Program.cs index 911474d..eb38880 100644 --- a/sandbox/MultiContainedApp/Program.cs +++ b/sandbox/MultiContainedApp/Program.cs @@ -10,7 +10,7 @@ class Program { static async Task Main(string[] args) { - await BatchHost.CreateDefaultBuilder(useSimpleConosoleLogger:true) + await BatchHost.CreateDefaultBuilder() .RunBatchEngineAsync(args); } }