77using System . IO ;
88using System . Reflection ;
99using System . Collections . Generic ;
10+ using System . Linq ;
1011
1112namespace MicroBatchFramework
1213{
@@ -63,22 +64,22 @@ public static class BatchHost
6364 /// <returns>The initialized <see cref="IHostBuilder"/>.</returns>
6465 public static IHostBuilder CreateDefaultBuilder ( bool useSimpleConsoleLogger , LogLevel minSimpleConsoleLoggerLogLevel , string hostEnvironmentVariable )
6566 {
66- var builder = new HostBuilder ( ) ;
67+ var builder = Host . CreateDefaultBuilder ( ) ;
6768
6869 ConfigureHostConfigurationDefault ( builder , hostEnvironmentVariable ) ;
69- ConfigureAppConfigurationDefault ( builder ) ;
7070 ConfigureLoggingDefault ( builder , useSimpleConsoleLogger , minSimpleConsoleLoggerLogLevel ) ;
7171
7272 return builder ;
7373 }
7474
7575 internal static void ConfigureHostConfigurationDefault ( IHostBuilder builder , string hostEnvironmentVariable )
7676 {
77- builder . UseContentRoot ( Path . GetDirectoryName ( Assembly . GetExecutingAssembly ( ) . Location ) ) ;
78-
7977 builder . ConfigureHostConfiguration ( config =>
8078 {
79+ // NOTE: This is backward compatibility for v1.3.0 or before.
80+ // It's strongly recommended to use "DOTNET_" prefix expected by GenericHost. (e.g. DOTNET_ENVIRONMENT)
8181 config . AddEnvironmentVariables ( prefix : "NETCORE_" ) ;
82+
8283 config . AddInMemoryCollection ( new [ ] { new KeyValuePair < string , string > ( HostDefaults . ApplicationKey , Assembly . GetExecutingAssembly ( ) . GetName ( ) . Name ) } ) ;
8384 } ) ;
8485
@@ -88,35 +89,19 @@ internal static void ConfigureHostConfigurationDefault(IHostBuilder builder, str
8889 }
8990 }
9091
91- internal static void ConfigureAppConfigurationDefault ( IHostBuilder builder )
92- {
93- builder . ConfigureAppConfiguration ( ( hostingContext , config ) =>
94- {
95- var env = hostingContext . HostingEnvironment ;
96-
97- config . AddJsonFile ( "appsettings.json" , optional : true , reloadOnChange : true ) ;
98- config . AddJsonFile ( $ "appsettings.{ env . EnvironmentName } .json", optional : true , reloadOnChange : true ) ;
99-
100- if ( env . IsDevelopment ( ) )
101- {
102- var appAssembly = Assembly . Load ( new AssemblyName ( env . ApplicationName ) ) ;
103- if ( appAssembly != null )
104- {
105- // use https://marketplace.visualstudio.com/items?itemName=guitarrapc.OpenUserSecrets to easily manage UserSecrets with GenericHost.
106- config . AddUserSecrets ( appAssembly , optional : true ) ;
107- }
108- }
109-
110- config . AddEnvironmentVariables ( ) ;
111- } ) ;
112- }
113-
11492 internal static void ConfigureLoggingDefault ( IHostBuilder builder , bool useSimpleConsoleLogger , LogLevel minSimpleConsoleLoggerLogLevel )
11593 {
11694 if ( useSimpleConsoleLogger )
11795 {
11896 builder . ConfigureLogging ( logging =>
11997 {
98+ // Use SimpleConsoleLogger instead of the default ConsoleLogger.
99+ var consoleLogger = logging . Services . FirstOrDefault ( x => x . ImplementationType ? . FullName == "Microsoft.Extensions.Logging.Console.ConsoleLoggerProvider" ) ;
100+ if ( consoleLogger != null )
101+ {
102+ logging . Services . Remove ( consoleLogger ) ;
103+ }
104+
120105 logging . AddSimpleConsole ( ) ;
121106 logging . AddFilter < SimpleConsoleLoggerProvider > ( ( category , level ) =>
122107 {
0 commit comments