namespace bdf
{
    using System;
    using System.Text;

    internal static class Logger
    {
        public static void Log(uint level, string format, params object[] objs)
        {
            StringBuilder sb = new StringBuilder();
	        sb.AppendFormat("[{0}] ", DateTime.Now);
            try
            {
                sb.AppendFormat(format, objs);
            }
            catch (FormatException e)
            {
                Console.WriteLine("Logger: invalid parameters for formatting. {0}:{1}", e.Message);
            }
            catch (ArgumentNullException e)
            {
                Console.WriteLine("Logger: invalid parameters for formatting. {0}:{1}", e.Message);
            }
            catch (IndexOutOfRangeException e)
            {
                Console.WriteLine("Logger: invalid parameters for formatting. {0}:{1}", e.Message);
            }
            catch (Exception e)
            {
                Console.WriteLine("Logger: invalid parameters for formatting. {0}:{1}", e.Message, e.InnerException.Message);
            }
            if (level <= bdf.debug )
            {
                Console.WriteLine(sb.ToString());
		        bdf.outfile.WriteLine(sb.ToString());
            }
            if (level <= bdf.adlvl )
            {
            	bdf.adminLog.AppendLine(sb.ToString());
            }
        }

		public static void Log(string message)
        {
            StringBuilder sb = new StringBuilder();
	        sb.AppendFormat("[{0}] {1}", DateTime.Now, message);
	        Console.WriteLine(sb.ToString());
		    bdf.outfile.WriteLine(sb.ToString());
            bdf.adminLog.AppendLine(sb.ToString());
            
		}

        public static void Log(string task, string format, params object[] objs)
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendFormat("[{0}] ", task);
            try
            {
                sb.AppendFormat(format, objs);
            }
            catch (FormatException e)
            {
                Console.WriteLine("Logger: invalid parameters for formatting. {0}:{1}", e.Message, e.InnerException.Message);
            }
            catch (ArgumentNullException e)
            {
                Console.WriteLine("Logger: invalid parameters for formatting. {0}:{1}", e.Message, e.InnerException.Message);
            }
            bdf.reportfile.WriteLine(sb.ToString());
            
        }
    }
}

