alielie
7 天以前 e57938fbda9bff702004038f76d009422968bff5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using 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);
            }
        }
    }
}