@@ -158,34 +158,31 @@ public static void ConfigureLoggerFactory(Action<ILoggingBuilder> configure) =>
158
158
//Creates a logging factory based on a JsonConfiguration in appsettings.json
159
159
private static ILoggerFactory GetDefaultLoggerFactory ( )
160
160
{
161
- ILoggerFactory ? configuredLoggingFactory = null ;
162
- try
161
+ string settingsPath = Path . Combine ( Directory . GetCurrentDirectory ( ) , "appsettings.json" ) ;
162
+ if ( ! File . Exists ( settingsPath ) )
163
163
{
164
- IConfigurationRoot configuration = new ConfigurationBuilder ( )
164
+ return ErrorLoggerFactory ;
165
+ }
166
+
167
+ IConfigurationRoot configuration = new ConfigurationBuilder ( )
165
168
. SetBasePath ( Directory . GetCurrentDirectory ( ) )
166
- . AddJsonFile ( "appsettings.json" , optional : true )
169
+ . AddJsonFile ( "appsettings.json" , optional : false )
167
170
. AddJsonFile ( "appsettings.Development.json" , optional : true )
168
171
. Build ( ) ;
169
172
170
- configuredLoggingFactory = Microsoft . Extensions . Logging . LoggerFactory . Create (
171
- builder =>
172
- {
173
- IConfigurationSection loggingSection = configuration . GetSection ( "Logging" ) ;
174
- _ = builder . AddConfiguration ( loggingSection ) ;
175
- _ = builder . AddConsole ( ) ;
176
- } ) ;
177
- }
178
- #pragma warning disable CA1031
179
- catch ( Exception e )
180
- #pragma warning restore CA1031
181
- {
182
- Console . Error . WriteLine ( e ) ;
183
- }
173
+ return Microsoft . Extensions . Logging . LoggerFactory . Create (
174
+ builder =>
175
+ {
176
+ IConfigurationSection loggingSection = configuration . GetSection ( "Logging" ) ;
177
+ _ = builder
178
+ . AddConfiguration ( loggingSection )
179
+ . AddConsole ( ) ;
180
+ } ) ;
181
+ }
184
182
185
- return configuredLoggingFactory ?? Microsoft . Extensions . Logging . LoggerFactory . Create (
183
+ private static ILoggerFactory ErrorLoggerFactory => Microsoft . Extensions . Logging . LoggerFactory . Create (
186
184
builder => builder
187
185
. AddConsole ( )
188
186
. SetMinimumLevel ( LogLevel . Error ) ) ;
189
- }
190
187
}
191
188
}
0 commit comments