|
|
|
@ -69,14 +69,7 @@ namespace Lib.Logging |
|
|
|
/// </summary> |
|
|
|
/// </summary> |
|
|
|
/// <param name="ex">The <see cref="Exception"/></param> |
|
|
|
/// <param name="ex">The <see cref="Exception"/></param> |
|
|
|
/// <typeparam name="T">The <see cref="Type"/> of the caller</typeparam> |
|
|
|
/// <typeparam name="T">The <see cref="Type"/> of the caller</typeparam> |
|
|
|
public static async Task Write<T>(Exception ex) |
|
|
|
public static async Task Write<T>(Exception ex) => await Write(GetDefaultComponentFromType<T>(), ex); |
|
|
|
{ |
|
|
|
|
|
|
|
ILogComponent component = GetDefaultComponentFromType<T>(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await Write(component, LogLevels.Error, ex.Message); |
|
|
|
|
|
|
|
await Write(component, LogLevels.Error, ""); |
|
|
|
|
|
|
|
await Write(component, LogLevels.Error, ex.StackTrace); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// <summary> |
|
|
|
/// Write a given <see cref="Exception"/> to the set <see cref="ILogger"/>s |
|
|
|
/// Write a given <see cref="Exception"/> to the set <see cref="ILogger"/>s |
|
|
|
@ -87,6 +80,8 @@ namespace Lib.Logging |
|
|
|
{ |
|
|
|
{ |
|
|
|
await Write(component, LogLevels.Error, ex.Message); |
|
|
|
await Write(component, LogLevels.Error, ex.Message); |
|
|
|
await Write(component, LogLevels.Error, ""); |
|
|
|
await Write(component, LogLevels.Error, ""); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (ex.StackTrace != null) |
|
|
|
await Write(component, LogLevels.Error, ex.StackTrace); |
|
|
|
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, ex.Message); |
|
|
|
await Write(component, LogLevels.Error, ""); |
|
|
|
await Write(component, LogLevels.Error, ""); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (ex.StackTrace != null) |
|
|
|
|
|
|
|
{ |
|
|
|
await Write(component, LogLevels.Error, ex.StackTrace); |
|
|
|
await Write(component, LogLevels.Error, ex.StackTrace); |
|
|
|
await Write(component, LogLevels.Error, ""); |
|
|
|
await Write(component, LogLevels.Error, ""); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
foreach (var innerException in ex.InnerExceptions) |
|
|
|
foreach (var innerException in ex.InnerExceptions) |
|
|
|
{ |
|
|
|
{ |
|
|
|
@ -128,11 +127,7 @@ namespace Lib.Logging |
|
|
|
/// <param name="logLevel">The <see cref="LogLevels"/></param> |
|
|
|
/// <param name="logLevel">The <see cref="LogLevels"/></param> |
|
|
|
/// <param name="line">The given <see cref="string"/></param> |
|
|
|
/// <param name="line">The given <see cref="string"/></param> |
|
|
|
/// <typeparam name="T">The <see cref="Type"/> of the caller</typeparam> |
|
|
|
/// <typeparam name="T">The <see cref="Type"/> of the caller</typeparam> |
|
|
|
public static async Task Write<T>(LogLevels logLevel, string line) |
|
|
|
public static async Task Write<T>(LogLevels logLevel, string line) => await Write(GetDefaultComponentFromType<T>(), logLevel, line); |
|
|
|
{ |
|
|
|
|
|
|
|
ILogComponent component = GetDefaultComponentFromType<T>(); |
|
|
|
|
|
|
|
await Write(component, logLevel, line); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// <summary> |
|
|
|
/// Write a given <see cref="string"/> with the <see cref="ILogComponent"/> and the <see cref="LogLevels"/> to the set <see cref="ILogger"/>s |
|
|
|
/// Write a given <see cref="string"/> with the <see cref="ILogComponent"/> and the <see cref="LogLevels"/> to the set <see cref="ILogger"/>s |
|
|
|
@ -146,7 +141,7 @@ namespace Lib.Logging |
|
|
|
if (logLevel > LogLevel) //logLevel of the message can't be higher than the set LogLevel |
|
|
|
if (logLevel > LogLevel) //logLevel of the message can't be higher than the set LogLevel |
|
|
|
return; |
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
ILogMessage message = new LogMessage() |
|
|
|
ILogMessage message = new LogMessage |
|
|
|
{ |
|
|
|
{ |
|
|
|
LogLevel = logLevel, |
|
|
|
LogLevel = logLevel, |
|
|
|
Timestamp = DateTime.Now, |
|
|
|
Timestamp = DateTime.Now, |
|
|
|
@ -158,10 +153,8 @@ namespace Lib.Logging |
|
|
|
throw new LogNotInitializedException(); |
|
|
|
throw new LogNotInitializedException(); |
|
|
|
|
|
|
|
|
|
|
|
foreach (var logger in Loggers) |
|
|
|
foreach (var logger in Loggers) |
|
|
|
{ |
|
|
|
|
|
|
|
await logger.Write(message); |
|
|
|
await logger.Write(message); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// <summary> |
|
|
|
/// Get the default <see cref="ILogComponent"/> for the given <see cref="Assembly"/> |
|
|
|
/// Get the default <see cref="ILogComponent"/> for the given <see cref="Assembly"/> |
|
|
|
@ -170,8 +163,8 @@ namespace Lib.Logging |
|
|
|
/// <returns></returns> |
|
|
|
/// <returns></returns> |
|
|
|
protected static ILogComponent GetDefaultComponentFromType<T>() |
|
|
|
protected static ILogComponent GetDefaultComponentFromType<T>() |
|
|
|
{ |
|
|
|
{ |
|
|
|
Assembly assembly = Assembly.GetAssembly(typeof(T)); |
|
|
|
Assembly? assembly = Assembly.GetAssembly(typeof(T)); |
|
|
|
LogComponentAttribute attribute = assembly.GetCustomAttribute<LogComponentAttribute>(); |
|
|
|
LogComponentAttribute? attribute = assembly?.GetCustomAttribute<LogComponentAttribute>(); |
|
|
|
return attribute ?? new LogComponentAttribute("UNKNOWN"); |
|
|
|
return attribute ?? new LogComponentAttribute("UNKNOWN"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -198,9 +191,7 @@ namespace Lib.Logging |
|
|
|
if (Loggers != null) |
|
|
|
if (Loggers != null) |
|
|
|
{ |
|
|
|
{ |
|
|
|
foreach (var logger in Loggers) |
|
|
|
foreach (var logger in Loggers) |
|
|
|
{ |
|
|
|
|
|
|
|
await logger.DisposeAsync(); |
|
|
|
await logger.DisposeAsync(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Loggers.Clear(); |
|
|
|
Loggers.Clear(); |
|
|
|
} |
|
|
|
} |
|
|
|
|