namespace OubHackMS.Logging
{
    using OubHackMS.Core;
    using System;
    using System.Collections.Generic;
    using System.Reflection;

    internal class Logger : LinkedClass
    {
        private Dictionary<Level, LoggingHandler> dHandlers = new Dictionary<Level, LoggingHandler>();

        public Logger()
        {
            Type[] types = Assembly.GetCallingAssembly().GetTypes();
            for (int i = 0; i < types.Length; i++)
            {
                if (types[i].Namespace == "OubHackMS.Logging.Handlers")
                {
                    LoggingHandler handler = (LoggingHandler) Activator.CreateInstance(types[i], new object[] { base.parent });
                    this.dHandlers.Add(handler.handleKey, handler);
                }
            }
        }

        public void Log(Level level, params object[] oArgs)
        {
            if (this.dHandlers.ContainsKey(level))
            {
                this.dHandlers[level].onLog(oArgs);
            }
            else
            {
                Console.WriteLine("!! WARNING !! Attempted to log with level " + level.ToString() + " which has no logger!");
            }
        }
    }
}

