using System;

namespace ZionVault.Logger
{
    class LogWindows : ILog
    {
        private static object CurrentLock = new Object();

        public enum LogType
        {
            DEBUG,
            ERROR,
            INFO
        }

        public void debug(string message)
        {
            lock (CurrentLock)
            {
                WriteLog(LogType.DEBUG, message);
            }
        }

        public void error(string message)
        {
            lock (CurrentLock)
            {
                WriteLog(LogType.ERROR, message);
            }
        }

        public void info(string message)
        {
            lock (CurrentLock)
            {
                WriteLog(LogType.INFO, message);
            }
        }

        private void WriteLog(LogType Type, string Message)
        {
            lock (CurrentLock)
            {
                string source = "OnSet ZionSchematics";
                string app = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name;

                if (!System.Diagnostics.EventLog.SourceExists(source))
                    System.Diagnostics.EventLog.CreateEventSource(source, app);

                switch (Type)
                {
                    case LogType.DEBUG:
                        System.Diagnostics.EventLog.WriteEntry(source, Message, System.Diagnostics.EventLogEntryType.SuccessAudit);
                        break;
                    case LogType.ERROR:
                        System.Diagnostics.EventLog.WriteEntry(source, Message, System.Diagnostics.EventLogEntryType.Error);
                        break;
                    case LogType.INFO:
                        System.Diagnostics.EventLog.WriteEntry(source, Message, System.Diagnostics.EventLogEntryType.Information);
                        break;
                }
            }
        }
    }
}
