Skip to content

Commit 8e635c5

Browse files
committed
fix: Only error logs are given as default
1 parent b63881c commit 8e635c5

File tree

1 file changed

+17
-20
lines changed
  • Yubico.Core/src/Yubico/Core/Logging

1 file changed

+17
-20
lines changed

Yubico.Core/src/Yubico/Core/Logging/Log.cs

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -158,34 +158,31 @@ public static void ConfigureLoggerFactory(Action<ILoggingBuilder> configure) =>
158158
//Creates a logging factory based on a JsonConfiguration in appsettings.json
159159
private static ILoggerFactory GetDefaultLoggerFactory()
160160
{
161-
ILoggerFactory? configuredLoggingFactory = null;
162-
try
161+
string settingsPath = Path.Combine(Directory.GetCurrentDirectory(), "appsettings.json");
162+
if (!File.Exists(settingsPath))
163163
{
164-
IConfigurationRoot configuration = new ConfigurationBuilder()
164+
return ErrorLoggerFactory;
165+
}
166+
167+
IConfigurationRoot configuration = new ConfigurationBuilder()
165168
.SetBasePath(Directory.GetCurrentDirectory())
166-
.AddJsonFile("appsettings.json", optional: true)
169+
.AddJsonFile("appsettings.json", optional: false)
167170
.AddJsonFile("appsettings.Development.json", optional: true)
168171
.Build();
169172

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+
}
184182

185-
return configuredLoggingFactory ?? Microsoft.Extensions.Logging.LoggerFactory.Create(
183+
private static ILoggerFactory ErrorLoggerFactory => Microsoft.Extensions.Logging.LoggerFactory.Create(
186184
builder => builder
187185
.AddConsole()
188186
.SetMinimumLevel(LogLevel.Error));
189-
}
190187
}
191188
}

0 commit comments

Comments
 (0)