44using Microsoft . Extensions . DependencyInjection ;
55using Microsoft . Extensions . Hosting ;
66using Microsoft . Extensions . Logging ;
7- using System ;
87using System . Collections . Generic ;
98using System . Drawing ;
109using System . IO ;
@@ -30,13 +29,13 @@ internal static IHostBuilder CreateDefaultBuilder(HostBuilderOptions options)
3029
3130 var defaultConfigName = ! string . IsNullOrWhiteSpace ( options . ConfigFile ) ? Path . GetFileName ( options . ConfigFile ) : "appsettings.json" ;
3231
33-
3432 if ( options . Verbose )
3533 {
3634 Console . WriteLine ( $ "ContentRoot:{ fullPath } ", color : Color . Green ) ;
3735 }
3836
3937 builder
38+ . UseStartupFilter ( )
4039 . ConfigureAppConfiguration ( ( context , config ) =>
4140 {
4241 // appsettings file or others
@@ -70,7 +69,23 @@ internal static IHostBuilder CreateDefaultBuilder(HostBuilderOptions options)
7069 config . AddAzureKeyVault ( hostingEnviromentName : options . HostingEnviroment , options . UseAzureKeyPrefix ) ;
7170 }
7271
73- if ( options . Verbose )
72+ if ( ! string . IsNullOrWhiteSpace ( options . Settings . ClientId )
73+ && ! string . IsNullOrWhiteSpace ( options . Settings . ClientSecret ) )
74+ {
75+ var inputValues = new Dictionary < string , string >
76+ {
77+ { $ "{ options . SectionName } :ClientId", options . Settings . ClientId } ,
78+ { $ "{ options . SectionName } :ClientSecret", options . Settings . ClientSecret } ,
79+ { $ "{ options . SectionName } :LoginUrl", options . Settings . LoginUrl } ,
80+ { $ "{ options . SectionName } :OAuthUri", options . Settings . OAuthUri } ,
81+ { $ "{ options . SectionName } :OAuthorizeUri", options . Settings . OAuthorizeUri } ,
82+ } ;
83+
84+ config . AddInMemoryCollection ( inputValues ) ;
85+ }
86+
87+ if ( options . Verbose && options . Level == LogLevel . Debug
88+ || options . Level == LogLevel . Trace )
7489 {
7590 config . Build ( ) . DebugConfigurations ( ) ;
7691 }
@@ -98,7 +113,10 @@ internal static IHostBuilder CreateDefaultBuilder(HostBuilderOptions options)
98113
99114 if ( options . Verbose )
100115 {
101- services . AddLogging ( x => x . AddFilter ( ( _ ) => true ) ) ;
116+ services . AddLogging ( x => x . AddFilter ( ( loglevel ) =>
117+ {
118+ return loglevel == options . Level ;
119+ } ) ) ;
102120 }
103121
104122 services . AddSingleton ( PhysicalConsole . Singleton ) ;
0 commit comments