using System;
using System.Diagnostics;

namespace Log
{
    public static class Log
    {
        public static void Init(string logPath)
        {
            Debug.Listeners.Clear();
            Debug.Listeners.Add(new TextWriterTraceListener(logPath));
            Debug.AutoFlush = true;
        }
        public static void D(string message)
        {
            var sf = new StackFrame(1, true);
            string log = string.Format(
                "{0} {1} Line:{2} {3} [D]: {4}",
                System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                sf.GetFileName(),
                sf.GetFileLineNumber(),
                sf.GetMethod(),
                message
            );
            Debug.WriteLine(log);
        }
        public static void D(string message, params object[] args)
        {
            string info = String.Format(message, args);
            var sf = new StackFrame(1, true);
            string log = string.Format(
                "{0} {1} Line:{2} {3} [D]: {4}",
                System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                sf.GetFileName(),
                sf.GetFileLineNumber(),
                sf.GetMethod(),
                info
            );
            Debug.WriteLine(log);
        }

        public static void E(string message)
        {
            var sf = new StackFrame(1, true);
            string log = string.Format(
                "{0} {1} Line:{2} {3} [E]: {4}",
                System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                sf.GetFileName(),
                sf.GetFileLineNumber(),
                sf.GetMethod(),
                message
            );
            Debug.WriteLine(log);
        }
        public static void E(string message, params object[] args)
        {
            string info = String.Format(message, args);
            var sf = new StackFrame(1, true);
            string log = string.Format(
                "{0} {1} Line:{2} {3} [E]: {4}",
                System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                sf.GetFileName(),
                sf.GetFileLineNumber(),
                sf.GetMethod(),
                info
            );
            Debug.WriteLine(log);
        }
    }
}