From 3f49c0cd965d023b35ac9e83691c7e016104fa57 Mon Sep 17 00:00:00 2001 From: sanji Date: Thu, 30 Nov 2023 16:09:29 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=97=E8=A1=A8=E6=90=9C=E7=B4=A2=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0UV?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SBF.Common/Log/NLogManager.cs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 SBF.Common/Log/NLogManager.cs diff --git a/SBF.Common/Log/NLogManager.cs b/SBF.Common/Log/NLogManager.cs new file mode 100644 index 0000000..7558afc --- /dev/null +++ b/SBF.Common/Log/NLogManager.cs @@ -0,0 +1,34 @@ +using NLog; +using System.Collections.Concurrent; + +namespace SBF.Common.Log +{ + public class NLogManager + { + private ConcurrentDictionary loggerDictionary; + private string defaultLoggerName = "default"; + + public NLogManager() + { + loggerDictionary = new ConcurrentDictionary(); + loggerDictionary.TryAdd("default", NLog.LogManager.GetLogger(defaultLoggerName)); + } + + public ILogger Default() + { + return loggerDictionary[defaultLoggerName]; + } + + public ILogger GetLogger(string loggerName) + { + if (string.IsNullOrEmpty(loggerName)) + return Default(); + if (!loggerDictionary.TryGetValue(loggerName, out ILogger logger)) + { + logger = NLog.LogManager.GetLogger(loggerName); + loggerDictionary.TryAdd(loggerName, logger); + } + return logger; + } + } +}