using NLog;
using System.Collections.Generic;

namespace Binance.TradeRobot.Business
{
    public class NLogManager
    {
        private IDictionary<string, ILogger> loggerDictionary = new Dictionary<string, ILogger>();
        private string defaultLoggerName = "default";

        public NLogManager()
        {
            loggerDictionary = new Dictionary<string, ILogger>()
            {
                { "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;
        }
    }
}