Skip to content

Commit

Permalink
Fixed serilog in production
Browse files Browse the repository at this point in the history
(cherry picked from commit d2238b9)
  • Loading branch information
niklasstich committed Sep 12, 2023
1 parent 7e03e94 commit 6ae8bc3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
25 changes: 18 additions & 7 deletions AuthoringTool/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
using Presentation.PresentationLogic.MyLearningWorlds;
using Presentation.PresentationLogic.SelectedViewModels;
using Serilog;
using Serilog.Settings.Configuration;
using Serilog.Sinks.SystemConsole.Themes;
using Shared;
using Shared.Configuration;
Expand Down Expand Up @@ -75,13 +76,23 @@ public void ConfigureServices(IServiceCollection services)

var logFileName = Environment.IsDevelopment() ? "log-dev.txt" : "log.txt";
var logFilePath = Path.Combine(ApplicationPaths.LogsFolder, logFileName);
Log.Logger = new LoggerConfiguration()
.ReadFrom.Configuration(Configuration)
.Enrich.FromLogContext()
.WriteTo.Console(theme: AnsiConsoleTheme.Code)
.WriteTo.File(path: logFilePath, buffered: false, rollOnFileSizeLimit: true, fileSizeLimitBytes: 100000000,
retainedFileCountLimit: 5)
.CreateLogger();
try
{
var options = new ConfigurationReaderOptions(typeof(ConsoleLoggerExtensions).Assembly);
var loggerConfig = new LoggerConfiguration();
loggerConfig.ReadFrom.Configuration(Configuration, options)
.Enrich.FromLogContext()
.WriteTo.Console(theme: AnsiConsoleTheme.Code)
.WriteTo.File(path: logFilePath, buffered: false, rollOnFileSizeLimit: true,
fileSizeLimitBytes: 100000000,
retainedFileCountLimit: 5);
Log.Logger = loggerConfig.CreateLogger();
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}

services.AddLogging(builder =>
{
Expand Down
2 changes: 1 addition & 1 deletion AuthoringTool/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"Serilog": {
"MinimumLevel": {
"Default": "Trace",
"Default": "Verbose",
"Override": {
"Microsoft": "Warning",
"Microsoft.AspNetCore": "Warning",
Expand Down

0 comments on commit 6ae8bc3

Please sign in to comment.