diff --git a/Lib.Logging/Log.cs b/Lib.Logging/Log.cs index 0af8e1e..c371625 100644 --- a/Lib.Logging/Log.cs +++ b/Lib.Logging/Log.cs @@ -69,14 +69,7 @@ namespace Lib.Logging /// /// The /// The of the caller - public static async Task Write(Exception ex) - { - ILogComponent component = GetDefaultComponentFromType(); - - await Write(component, LogLevels.Error, ex.Message); - await Write(component, LogLevels.Error, ""); - await Write(component, LogLevels.Error, ex.StackTrace); - } + public static async Task Write(Exception ex) => await Write(GetDefaultComponentFromType(), ex); /// /// Write a given to the set s @@ -87,7 +80,9 @@ namespace Lib.Logging { await Write(component, LogLevels.Error, ex.Message); await Write(component, LogLevels.Error, ""); - await Write(component, LogLevels.Error, ex.StackTrace); + + if (ex.StackTrace != null) + await Write(component, LogLevels.Error, ex.StackTrace); } /// @@ -101,8 +96,12 @@ namespace Lib.Logging await Write(component, LogLevels.Error, ex.Message); await Write(component, LogLevels.Error, ""); - await Write(component, LogLevels.Error, ex.StackTrace); - await Write(component, LogLevels.Error, ""); + + if (ex.StackTrace != null) + { + await Write(component, LogLevels.Error, ex.StackTrace); + await Write(component, LogLevels.Error, ""); + } foreach (var innerException in ex.InnerExceptions) { @@ -128,11 +127,7 @@ namespace Lib.Logging /// The /// The given /// The of the caller - public static async Task Write(LogLevels logLevel, string line) - { - ILogComponent component = GetDefaultComponentFromType(); - await Write(component, logLevel, line); - } + public static async Task Write(LogLevels logLevel, string line) => await Write(GetDefaultComponentFromType(), logLevel, line); /// /// Write a given with the and the to the set s @@ -146,7 +141,7 @@ namespace Lib.Logging if (logLevel > LogLevel) //logLevel of the message can't be higher than the set LogLevel return; - ILogMessage message = new LogMessage() + ILogMessage message = new LogMessage { LogLevel = logLevel, Timestamp = DateTime.Now, @@ -157,10 +152,8 @@ namespace Lib.Logging if (Loggers == null) throw new LogNotInitializedException(); - foreach (var logger in Loggers) - { + foreach (var logger in Loggers) await logger.Write(message); - } } /// @@ -170,8 +163,8 @@ namespace Lib.Logging /// protected static ILogComponent GetDefaultComponentFromType() { - Assembly assembly = Assembly.GetAssembly(typeof(T)); - LogComponentAttribute attribute = assembly.GetCustomAttribute(); + Assembly? assembly = Assembly.GetAssembly(typeof(T)); + LogComponentAttribute? attribute = assembly?.GetCustomAttribute(); return attribute ?? new LogComponentAttribute("UNKNOWN"); } @@ -197,10 +190,8 @@ namespace Lib.Logging { if (Loggers != null) { - foreach (var logger in Loggers) - { + foreach (var logger in Loggers) await logger.DisposeAsync(); - } Loggers.Clear(); } diff --git a/Lib.Logging/Loggers/FileLogger.cs b/Lib.Logging/Loggers/FileLogger.cs index d37b6d3..5168ac0 100644 --- a/Lib.Logging/Loggers/FileLogger.cs +++ b/Lib.Logging/Loggers/FileLogger.cs @@ -18,7 +18,7 @@ namespace Lib.Logging.Loggers private readonly StreamWriter _fileWriter; private readonly Timer _timer; - private readonly SemaphoreSlim _lockObject = new SemaphoreSlim(1); + private readonly SemaphoreSlim _lockObject = new(1); /// /// Constructor for @@ -49,7 +49,7 @@ namespace Lib.Logging.Loggers } } - private async void TimerCallback(object state) => await Flush(); + private async void TimerCallback(object? state) => await Flush(); private async Task Flush() { diff --git a/Lib.Logging/Properties/AssemblyInfo.cs b/Lib.Logging/Properties/AssemblyInfo.cs index ff6bf67..049501d 100644 --- a/Lib.Logging/Properties/AssemblyInfo.cs +++ b/Lib.Logging/Properties/AssemblyInfo.cs @@ -4,9 +4,4 @@ using Lib.Logging; -[assembly:LogComponent("LOGGING")] - -namespace Lib.Logging.Properties -{ - -} \ No newline at end of file +[assembly:LogComponent("LOGGING")] \ No newline at end of file diff --git a/Lib.Tools/Enumerables.cs b/Lib.Tools/Enumerables.cs index 620aa76..39936d1 100644 --- a/Lib.Tools/Enumerables.cs +++ b/Lib.Tools/Enumerables.cs @@ -18,10 +18,8 @@ namespace Lib.Tools public static IEnumerable ForEach(this IEnumerable enumerable, Action action) { IEnumerable list = enumerable.ToList(); - foreach (T item in list) - { + foreach (T item in list) action(item); - } return list; } diff --git a/Mystify.sln.DotSettings b/Mystify.sln.DotSettings index 36f067c..c144c85 100644 --- a/Mystify.sln.DotSettings +++ b/Mystify.sln.DotSettings @@ -1,6 +1,6 @@  <Policy Inspect="True" Prefix="" Suffix="" Style="AA_BB" /> <Policy Inspect="True" Prefix="" Suffix="" Style="AA_BB" /> - <Policy Inspect="True" Prefix="_" Suffix="" Style="aaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> <Policy Inspect="True" Prefix="" Suffix="" Style="AA_BB" /> True \ No newline at end of file