Skip to content

Commit

Permalink
Fixed a logging issue
Browse files Browse the repository at this point in the history
  • Loading branch information
JunaMeinhold committed May 28, 2024
1 parent 218fe6b commit 4a66680
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
12 changes: 11 additions & 1 deletion HexaEngine.Core/Application.cs
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,11 @@ public static string GetFolder(SpecialFolder folder)
};
}

/// <summary>
/// Gets the file log writer used for logging.
/// </summary>
public static LogFileWriter? LogFileWriter { get; private set; }

/// <summary>
/// Initializes the application and necessary subsystems.
/// </summary>
Expand All @@ -292,8 +297,13 @@ public static void Boot(GraphicsBackend graphicsBackend, AudioBackend audioBacke
#if DEBUG
GraphicsDebugging = true;
#endif
if (disableLogging)
if (!disableLogging)
{
CrashLogger.Initialize();
LogFileWriter = new("logs");
LoggerFactory.AddGlobalWriter(LogFileWriter);
}

FileSystem.Initialize();
ImGuiConsole.Initialize();

Expand Down
13 changes: 6 additions & 7 deletions HexaEngine.Core/Debugging/CrashLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@
/// </summary>
public static class CrashLogger
{
/// <summary>
/// Gets the file log writer used for crash logging.
/// </summary>
public static readonly LogFileWriter FileLogWriter = new("logs");

#nullable disable
private static HardwareInfo info;
private static Task task;
Expand All @@ -44,9 +39,13 @@ public static void Initialize()
{
logger.Log(ex);
}

AppDomain.CurrentDomain.ProcessExit += CurrentDomain_ProcessExit;
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
LoggerFactory.AddGlobalWriter(FileLogWriter);
}

private static void CurrentDomain_ProcessExit(object? sender, EventArgs e)
{
LoggerFactory.CloseAll();
}

private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
Expand Down

0 comments on commit 4a66680

Please sign in to comment.