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 _allLogger = new ConcurrentDictionary(); 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); } } } }