master
Tudor Stanciu 2021-12-05 22:40:13 +02:00
parent 329027f145
commit aae5a3523f
1 changed files with 6 additions and 5 deletions

View File

@ -33,7 +33,10 @@ namespace IdentityServer.Api
var connectionString = configuration.GetConnectionString("DatabaseConnection"); var connectionString = configuration.GetConnectionString("DatabaseConnection");
var loggingLevelParam = configuration.GetValue<string>("Logging:LogLevel:Default"); var loggingLevelParam = configuration.GetValue<string>("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 loggingLevelSwitch = new LoggingLevelSwitch(loggingLevel);
var columnOptions = new ColumnOptions(); var columnOptions = new ColumnOptions();
@ -43,17 +46,15 @@ namespace IdentityServer.Api
var mssqlSinkOptions = new MSSqlServerSinkOptions() { AutoCreateSqlTable = true, TableName = "__Logs" }; var mssqlSinkOptions = new MSSqlServerSinkOptions() { AutoCreateSqlTable = true, TableName = "__Logs" };
Serilog.Debugging.SelfLog.Enable(msg => Console.WriteLine(msg));
Log.Logger = new LoggerConfiguration() Log.Logger = new LoggerConfiguration()
.MinimumLevel.Verbose() .MinimumLevel.ControlledBy(loggingLevelSwitch)
.MinimumLevel.Override("Microsoft", LogEventLevel.Warning) .MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
.Enrich.FromLogContext() .Enrich.FromLogContext()
.WriteTo.Console() .WriteTo.Console()
.WriteTo.MSSqlServer(connectionString, mssqlSinkOptions, columnOptions: columnOptions) .WriteTo.MSSqlServer(connectionString, mssqlSinkOptions, columnOptions: columnOptions)
.CreateLogger(); .CreateLogger();
Serilog.Debugging.SelfLog.Enable(msg => Console.WriteLine(msg)); //Serilog.Debugging.SelfLog.Enable(msg => Console.WriteLine(msg));
try try
{ {