diff --git a/IPA.Loader/Logging/StandardLogger.cs b/IPA.Loader/Logging/StandardLogger.cs index 21702e8d..1edd8c58 100644 --- a/IPA.Loader/Logging/StandardLogger.cs +++ b/IPA.Loader/Logging/StandardLogger.cs @@ -1,4 +1,6 @@ -using IPA.Config; +#nullable enable + +using IPA.Config; using IPA.Logging.Printers; using IPA.Utilities; using System; @@ -23,7 +25,7 @@ namespace IPA.Logging /// public class StandardLogger : Logger { - private static readonly List defaultPrinters = new List() + private static readonly List defaultPrinters = new() { new GlobalLogFilePrinter() }; @@ -108,10 +110,10 @@ namespace IPA.Logging private static bool showTrace = false; private static volatile bool syncLogging = false; - private readonly List printers = new List(); - private readonly StandardLogger parent; + private readonly List printers = new(); + private readonly StandardLogger? parent; - private readonly Dictionary children = new Dictionary(); + private readonly Dictionary children = new(); /// /// Configures internal debug settings based on the config passed in. @@ -218,7 +220,7 @@ namespace IPA.Logging Sync = threadSync }); - if (sync) threadSync.Wait(); + if (sync) threadSync!.Wait(); } catch (InvalidOperationException) { @@ -227,7 +229,7 @@ namespace IPA.Logging } [ThreadStatic] - private static ManualResetEventSlim threadSync; + private static ManualResetEventSlim? threadSync; /// /// @@ -263,7 +265,7 @@ namespace IPA.Logging public StandardLogger Logger; public string Message; public DateTime Time; - public ManualResetEventSlim Sync; + public ManualResetEventSlim? Sync; } [ThreadStatic] @@ -272,13 +274,13 @@ namespace IPA.Logging /// Whether or not the calling thread is the logger thread. /// /// if the current thread is the logger thread, otherwise - public static bool IsOnLoggerThread => isOnLoggerThread ??= Thread.CurrentThread.ManagedThreadId == logThread.ManagedThreadId; + public static bool IsOnLoggerThread => isOnLoggerThread ??= Thread.CurrentThread.ManagedThreadId == logThread?.ManagedThreadId; - private static readonly ManualResetEventSlim logWaitEvent = new ManualResetEventSlim(true); - private static readonly BlockingCollection logQueue = new BlockingCollection(); - private static Thread logThread; + private static readonly ManualResetEventSlim logWaitEvent = new(true); + private static readonly BlockingCollection logQueue = new(); + private static Thread? logThread; - private static StandardLogger loggerLogger; + private static StandardLogger? loggerLogger; private const int LogCloseTimeout = 250; @@ -323,7 +325,7 @@ namespace IPA.Logging if (!started.Contains(printer)) { // start printer if not started printer.StartPrint(); - started.Add(printer); + _ = started.Add(printer); } // update last use time and print @@ -355,13 +357,13 @@ namespace IPA.Logging { // aggregate loggers in the process var messageLogger = message.Logger; foreach (var print in messageLogger.printers) - prints.Add(print); + _ = prints.Add(print); do { messageLogger = messageLogger.parent; if (messageLogger != null) foreach (var print in messageLogger.printers) - prints.Add(print); + _ = prints.Add(print); } while (messageLogger != null); message.Sync?.Set(); @@ -397,7 +399,7 @@ namespace IPA.Logging Console.WriteLine($"printer errored: {e}"); } - started.Remove(printer); + _ = started.Remove(printer); } } } @@ -432,7 +434,7 @@ namespace IPA.Logging internal static void StopLogThread() { logQueue.CompleteAdding(); - logThread.Join(); + logThread!.Join(); } } @@ -448,11 +450,10 @@ namespace IPA.Logging /// the name of the child /// the child logger public static Logger GetChildLogger(this Logger logger, string name) - { - if (logger is StandardLogger standardLogger) - return standardLogger.GetChild(name); - - throw new InvalidOperationException(); - } + => logger switch + { + StandardLogger l => l.GetChild(name), + _ => throw new InvalidOperationException() + }; } } \ No newline at end of file