Added logging building function to LogOption for creating ILogger instasnces

This commit is contained in:
Max 2024-05-04 14:49:32 +02:00
parent a62896cf9f
commit 68403245f0
2 changed files with 8 additions and 3 deletions

View File

@ -9,4 +9,10 @@ public class LogOptions
/// The severty the logger will log /// The severty the logger will log
/// </summary> /// </summary>
public LogSeverity Severity { get; set; } = LogSeverity.Trace; public LogSeverity Severity { get; set; } = LogSeverity.Trace;
/// <summary>
/// The function that will build and return the <see cref="ILogger"/> when calling <see cref="LogService.RegisterLogger"/>, so a custom logger can be used.
/// </summary>
public Func<string, CallingSource, Action<LogCapsule>, ILogger> LoggerBuilder { get; set; } =
(identifier, source, sendEvent) => new Logger(identifier, source, ref sendEvent);
} }

View File

@ -46,13 +46,12 @@ public static class LogService
/// } /// }
/// </code> /// </code>
/// </example> /// </example>
/// <remarks>At the moment this function will only return the default <see cref="Logger"/> class, this is not configureble at the moment!</remarks>
/// <param name="identifier">The identifier name of the logger, this will be passed to the log adapter as the source.</param> /// <param name="identifier">The identifier name of the logger, this will be passed to the log adapter as the source.</param>
/// <returns>The configured <see cref="ILogger"/> implementation that will be configuered in the <see cref="LogOptions"/> at the <see cref="LogService"/> class</returns> /// <returns>The configured <see cref="ILogger"/> implementation that will be configuered in the <see cref="LogOptions.LoggerBuilder"/> at the <see cref="LogService"/> class</returns>
public static ILogger RegisterLogger(string identifier) public static ILogger RegisterLogger(string identifier)
{ {
var asm = Assembly.GetCallingAssembly(); var asm = Assembly.GetCallingAssembly();
var logger = new Logger(identifier, CallingSource.LoadFromAsm(asm), ref _loggerSendEvent); var logger = Options.LoggerBuilder.Invoke(identifier, CallingSource.LoadFromAsm(asm), _loggerSendEvent);
Loggers.Add(logger); Loggers.Add(logger);
return logger; return logger;
} }