Adjusted GC.KeepAlive

This commit is contained in:
XorogVEVO 2022-03-19 17:36:04 +01:00
parent f0bcebbd10
commit 5550909851

View file

@ -25,8 +25,6 @@ public class Logger
/// <returns>A bool stating if the logger was started</returns>
public static void StartLogger(string filePath = "", LoggerObjects.LogLevel level = LoggerObjects.LogLevel.DEBUG, DateTime cleanUpBefore = new DateTime(), bool ThrowOnFailedDeletion = false)
{
GC.KeepAlive(_loggerObjects.LogsToPost);
if (loggerStarted)
throw new Exception($"The logger is already started");
@ -83,11 +81,6 @@ public class Logger
continue;
}
GC.KeepAlive(b);
GC.KeepAlive(b.LogLevel);
GC.KeepAlive(b.Message);
GC.KeepAlive(b.TimeOfEvent);
string LogLevelText = b.LogLevel.ToString();
if (LogLevelText.Length != 5)
@ -173,6 +166,11 @@ public class Logger
{
LogFatal($"Couldn't write log to file: {ex}");
}
GC.KeepAlive(b);
GC.KeepAlive(b.LogLevel);
GC.KeepAlive(b.Message);
GC.KeepAlive(b.TimeOfEvent);
}
}
catch (Exception ex)
@ -185,6 +183,8 @@ public class Logger
}
}
});
GC.KeepAlive(_loggerObjects.LogsToPost);
}