From e32f68165d82c1a6e1adc36bb79f19a19ff9d43c Mon Sep 17 00:00:00 2001 From: shanji <18996038927@163.com> Date: Tue, 20 Feb 2024 22:00:30 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=B6=88=E6=81=AF=E5=8F=91?= =?UTF-8?q?=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- QYMessageCenter.Common/Log/NLogManager.cs | 34 +++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 QYMessageCenter.Common/Log/NLogManager.cs diff --git a/QYMessageCenter.Common/Log/NLogManager.cs b/QYMessageCenter.Common/Log/NLogManager.cs new file mode 100644 index 0000000..a65f46b --- /dev/null +++ b/QYMessageCenter.Common/Log/NLogManager.cs @@ -0,0 +1,34 @@ +using NLog; +using System.Collections.Concurrent; + +namespace QYMessageCenter.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; + } + } +}