From 8050c9c1947b46a9fc5384e708cdfd3c39ac2e56 Mon Sep 17 00:00:00 2001 From: sebastian-heinz Date: Fri, 20 Jan 2023 16:45:00 +0800 Subject: [PATCH] add configure method --- .version | 2 +- Arrowgene.Logging.Test/LogProviderTest.cs | 5 ++--- Arrowgene.Logging.Test/TestLogger.cs | 8 +++++++- Arrowgene.Logging/ILogger.cs | 8 ++------ Arrowgene.Logging/LogProvider.cs | 17 +++++++++-------- Arrowgene.Logging/Logger.cs | 12 +++++++++--- 6 files changed, 30 insertions(+), 22 deletions(-) diff --git a/.version b/.version index 867e524..cb174d5 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -1.2.0 \ No newline at end of file +1.2.1 \ No newline at end of file diff --git a/Arrowgene.Logging.Test/LogProviderTest.cs b/Arrowgene.Logging.Test/LogProviderTest.cs index 8d4249e..943e5a7 100644 --- a/Arrowgene.Logging.Test/LogProviderTest.cs +++ b/Arrowgene.Logging.Test/LogProviderTest.cs @@ -7,10 +7,9 @@ public class LogProviderTest { private class TestNsLogger : TestLogger { - public override void Initialize(string identity, string name, Action write, object loggerTypeTag, - object identityTag) + public override void Configure(object loggerTypeConfig, object identityConfig) { - Assert.Equal("Arrowgene.Logging.Test", identityTag); + Assert.Equal("Arrowgene.Logging.Test", identityConfig); } } diff --git a/Arrowgene.Logging.Test/TestLogger.cs b/Arrowgene.Logging.Test/TestLogger.cs index 1923ad2..eb462a3 100644 --- a/Arrowgene.Logging.Test/TestLogger.cs +++ b/Arrowgene.Logging.Test/TestLogger.cs @@ -4,8 +4,14 @@ namespace Arrowgene.Logging.Test; public class TestLogger : ILogger { - public virtual void Initialize(string identity, string name, Action write, object loggerTypeTag, object identityTag) + public void Initialize(string identity, string name, Action write) { + + } + + public virtual void Configure(object loggerTypeConfig, object identityConfig) + { + } public virtual void Write(LogLevel logLevel, string message, object tag) diff --git a/Arrowgene.Logging/ILogger.cs b/Arrowgene.Logging/ILogger.cs index b70f9ce..75d58b2 100644 --- a/Arrowgene.Logging/ILogger.cs +++ b/Arrowgene.Logging/ILogger.cs @@ -4,12 +4,8 @@ namespace Arrowgene.Logging { public interface ILogger { - void Initialize(string identity, - string name, Action write, - object loggerTypeTag, - object identityTag - ); - + void Initialize(string identity, string name, Action write); + void Configure(object loggerTypeConfig, object identityConfig); void Write(LogLevel logLevel, string message, object tag); void Trace(string message); void Info(string message); diff --git a/Arrowgene.Logging/LogProvider.cs b/Arrowgene.Logging/LogProvider.cs index 398ac0c..5837c8e 100644 --- a/Arrowgene.Logging/LogProvider.cs +++ b/Arrowgene.Logging/LogProvider.cs @@ -99,20 +99,20 @@ public static ILogger Logger(Type type) { if (!Loggers.TryGetValue(identity, out logger)) { - object loggerTypeTag = null; + object loggerTypeConfig = null; string loggerTypeName = typeof(T).FullName; if (loggerTypeName != null && LoggerTypeConfigurations.ContainsKey(loggerTypeName)) { - loggerTypeTag = LoggerTypeConfigurations[loggerTypeName]; + loggerTypeConfig = LoggerTypeConfigurations[loggerTypeName]; } - object identityTag = null; + object identityConfig = null; string searchNs = identity; while (true) { if (NamespaceConfigurations.ContainsKey(searchNs)) { - identityTag = NamespaceConfigurations[searchNs]; + identityConfig = NamespaceConfigurations[searchNs]; break; } int lastIdx = searchNs.LastIndexOf('.'); @@ -124,7 +124,8 @@ public static ILogger Logger(Type type) } logger = new T(); - logger.Initialize(identity, name, Write, loggerTypeTag, identityTag); + logger.Initialize(identity, name, Write); + logger.Configure(loggerTypeConfig, identityConfig); Loggers.Add(identity, logger); } } @@ -141,7 +142,7 @@ public static ILogger Logger(Type type) /// /// Provide a configuration object that will be passed to every instance /// that is created and inside the provided namespace - /// by calling on it. + /// by calling on it. /// public static void ConfigureNamespace(string ns, object configuration) { @@ -155,7 +156,7 @@ public static void ConfigureNamespace(string ns, object configuration) /// /// Provide a configuration object that will be passed to every instance - /// by calling on it. + /// by calling on it. /// public static void Configure(object configuration) where T : ILogger, new() { @@ -169,7 +170,7 @@ public static void Configure(Type type, object configuration) /// /// Provide a configuration object that will be passed to every instance - /// by calling on it. + /// by calling on it. /// public static void Configure(string identity, object configuration) { diff --git a/Arrowgene.Logging/Logger.cs b/Arrowgene.Logging/Logger.cs index 56b08ba..5ef393d 100644 --- a/Arrowgene.Logging/Logger.cs +++ b/Arrowgene.Logging/Logger.cs @@ -10,15 +10,21 @@ public class Logger : ILogger public virtual void Initialize(string identity, string name, - Action write, - object loggerTypeTag, - object identityTag + Action write ) { _identity = identity; _name = name; _write = write; } + + public virtual void Configure( + object loggerTypeConfig, + object identityConfig + ) + { + + } public void Write(Log log) {