From e57938fbda9bff702004038f76d009422968bff5 Mon Sep 17 00:00:00 2001
From: alielie <alielie@git.com>
Date: 星期五, 06 十一月 2026 18:05:07 +0800
Subject: [PATCH] 提交代码
---
DeviceService/Logging/GlobalLogger.cs | 63 +++++++++++++++++++++++++++++++
1 files changed, 63 insertions(+), 0 deletions(-)
diff --git a/DeviceService/Logging/GlobalLogger.cs b/DeviceService/Logging/GlobalLogger.cs
new file mode 100644
index 0000000..6b693de
--- /dev/null
+++ b/DeviceService/Logging/GlobalLogger.cs
@@ -0,0 +1,63 @@
+锘縰sing DeviceService.Core.Api;
+using log4net;
+using System.Collections.Concurrent;
+
+namespace DeviceService.Logging
+{
+ public class GlobalLogger : IServiceLogger
+ {
+ private static GlobalLogger? _logger;
+
+ public static GlobalLogger Logger => _logger ??= new GlobalLogger();
+
+ private static ConcurrentDictionary<string, ILog> _allLogger = new ConcurrentDictionary<string, ILog>();
+ private GlobalLogger()
+ {
+
+ }
+
+ private ILog GetLog(string source)
+ {
+ if (!_allLogger.ContainsKey(source))
+ {
+ _allLogger[source] = LogManager.GetLogger(source);
+ }
+ return _allLogger[source];
+ }
+
+ public void Debug(string source, string message)
+ {
+ GetLog(source).Debug(message);
+ }
+
+ public void Error(string source, string message, Exception ex = null)
+ {
+
+ if (ex == null)
+ {
+ GetLog(source).Error(message);
+ }
+ else
+ {
+ GetLog(source).Error(message, ex);
+ }
+ }
+
+ public void Info(string source, string message)
+ {
+ GetLog(source).Info(message);
+ }
+
+ public void Warn(string source, string message, Exception ex = null)
+ {
+ if (ex == null)
+ {
+ GetLog(source).Warn(message);
+ }
+ else
+ {
+ GetLog(source).Warn(message, ex);
+ }
+ }
+ }
+}
--
Gitblit v1.9.1