Skip to content

Commit

Permalink
Merge pull request #13 from mayuki/NoUseSimpleConsoleLoggerInBuilding…
Browse files Browse the repository at this point in the history
…BatchEngine

Remove SimpleConsoleLogger dependency from BatchEngine initialization.
  • Loading branch information
neuecc authored Apr 15, 2019
2 parents 4546b64 + 256fab5 commit f6a549c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 25 deletions.
3 changes: 2 additions & 1 deletion sandbox/MultiContainedApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ class Program
{
static async Task Main(string[] args)
{
await BatchHost.CreateDefaultBuilder().RunBatchEngineAsync(args);
await BatchHost.CreateDefaultBuilder()
.RunBatchEngineAsync(args);
}
}

Expand Down
22 changes: 6 additions & 16 deletions src/MicroBatchFramework/BatchEngineHostBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
{
Expand Down Expand Up @@ -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<T>(this IHostBuilder hostBuilder, string[] args, IBatchInterceptor interceptor = null, bool useSimpleConosoleLogger = true)
public static IHostBuilder UseBatchEngine<T>(this IHostBuilder hostBuilder, string[] args, IBatchInterceptor interceptor = null)
where T : BatchBase
{
var method = typeof(T).GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
Expand Down Expand Up @@ -151,18 +146,13 @@ public static IHostBuilder UseBatchEngine<T>(this IHostBuilder hostBuilder, stri
services.AddTransient<T>();
});

if (useSimpleConosoleLogger)
{
hostBuilder = hostBuilder.ConfigureLogging(x => x.AddSimpleConsole());
}

return hostBuilder.UseConsoleLifetime();
}

public static Task RunBatchEngineAsync<T>(this IHostBuilder hostBuilder, string[] args, IBatchInterceptor interceptor = null, bool useSimpleConosoleLogger = true)
public static Task RunBatchEngineAsync<T>(this IHostBuilder hostBuilder, string[] args, IBatchInterceptor interceptor = null)
where T : BatchBase
{
return UseBatchEngine<T>(hostBuilder, args, interceptor, useSimpleConosoleLogger).Build().RunAsync();
return UseBatchEngine<T>(hostBuilder, args, interceptor).Build().RunAsync();
}

static void ShowMethodList()
Expand Down
16 changes: 8 additions & 8 deletions src/MicroBatchFramework/BatchHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static class BatchHost
/// and configure the <see cref="SimpleConsoleLogger"/> to log to the console,
/// </remarks>
/// <returns>The initialized <see cref="IHostBuilder"/>.</returns>
public static IHostBuilder CreateDefaultBuilder(bool useSimpleConosoleLogger = true) => CreateDefaultBuilder(useSimpleConosoleLogger, LogLevel.Debug);
public static IHostBuilder CreateDefaultBuilder(bool useSimpleConsoleLogger = true) => CreateDefaultBuilder(useSimpleConsoleLogger, LogLevel.Debug);

/// <summary>
/// Initializes a new instance of the <see cref="HostBuilder"/> class with pre-configured defaults.
Expand All @@ -41,10 +41,10 @@ public static class BatchHost
/// load <see cref="IConfiguration"/> from environment variables,
/// and configure the <see cref="SimpleConsoleLogger"/> to log to the console,
/// </remarks>
/// <param name="useSimpleConosoleLogger"></param>
/// <param name="useSimpleConsoleLogger"></param>
/// <param name="minSimpleConsoleLoggerLogLevel"></param>
/// <returns>The initialized <see cref="IHostBuilder"/>.</returns>
public static IHostBuilder CreateDefaultBuilder(bool useSimpleConosoleLogger, LogLevel minSimpleConsoleLoggerLogLevel) => CreateDefaultBuilder(useSimpleConosoleLogger, minSimpleConsoleLoggerLogLevel, "");
public static IHostBuilder CreateDefaultBuilder(bool useSimpleConsoleLogger, LogLevel minSimpleConsoleLoggerLogLevel) => CreateDefaultBuilder(useSimpleConsoleLogger, minSimpleConsoleLoggerLogLevel, "");

/// <summary>
/// Initializes a new instance of the <see cref="HostBuilder"/> class with pre-configured defaults.
Expand All @@ -57,17 +57,17 @@ public static class BatchHost
/// load <see cref="IConfiguration"/> from environment variables,
/// and configure the <see cref="SimpleConsoleLogger"/> to log to the console,
/// </remarks>
/// <param name="useSimpleConosoleLogger"></param>
/// <param name="useSimpleConsoleLogger"></param>
/// <param name="minSimpleConsoleLoggerLogLevel"></param>
/// <param name="hostEnvironmentVariable"></param>
/// <returns>The initialized <see cref="IHostBuilder"/>.</returns>
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;
}
Expand Down Expand Up @@ -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 =>
{
Expand Down

0 comments on commit f6a549c

Please sign in to comment.