diff --git a/IdentityServer.Api/Program.cs b/IdentityServer.Api/Program.cs index 1c06f7a..68c1918 100644 --- a/IdentityServer.Api/Program.cs +++ b/IdentityServer.Api/Program.cs @@ -33,7 +33,10 @@ namespace IdentityServer.Api var connectionString = configuration.GetConnectionString("DatabaseConnection"); var loggingLevelParam = configuration.GetValue("Logging:LogLevel:Default"); - Enum.TryParse(loggingLevelParam, out LogEventLevel loggingLevel); + var loggingLevelOk = Enum.TryParse(loggingLevelParam, out LogEventLevel loggingLevel); + if (!loggingLevelOk) + throw new Exception($"Logging level '{loggingLevelParam}' is not valid."); + var loggingLevelSwitch = new LoggingLevelSwitch(loggingLevel); var columnOptions = new ColumnOptions(); @@ -43,17 +46,15 @@ namespace IdentityServer.Api var mssqlSinkOptions = new MSSqlServerSinkOptions() { AutoCreateSqlTable = true, TableName = "__Logs" }; - Serilog.Debugging.SelfLog.Enable(msg => Console.WriteLine(msg)); - Log.Logger = new LoggerConfiguration() - .MinimumLevel.Verbose() + .MinimumLevel.ControlledBy(loggingLevelSwitch) .MinimumLevel.Override("Microsoft", LogEventLevel.Warning) .Enrich.FromLogContext() .WriteTo.Console() .WriteTo.MSSqlServer(connectionString, mssqlSinkOptions, columnOptions: columnOptions) .CreateLogger(); - Serilog.Debugging.SelfLog.Enable(msg => Console.WriteLine(msg)); + //Serilog.Debugging.SelfLog.Enable(msg => Console.WriteLine(msg)); try {