using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace ParticleFramework
{
    static class Log
    {

        private static FileStream file;
        public static string dateTime = String.Format("{0:d/M/yyyy HH:mm:ss}", new DateTime());
        public static string logFile;

        public static Boolean Initialize(string f)
        {
            logFile = f;
            if (logFile != "")
            {
                try
                {
                    file = new FileStream(logFile, FileMode.Append);

                    //write out the startup
                    plainWrite("");
                    plainWrite("");
                    Info("Particle logging started");

                    return true;
                }
                catch
                {
                    return false;
                }
            }
            else
            {
                return false;
            }
        }

        public static void Info(string text)
        {
            text = "[" + dateTime + "] " + text;
            plainWrite(text);
        }

        public static void Error(string text)
        {
            text = "[ERROR] " + text;
            plainWrite(text);
        }

        private static void plainWrite(string text)
        {
            try
            {
                StreamWriter sw = new StreamWriter(file);

                sw.WriteLine(text);

                sw.Close();
                file = new FileStream(logFile, FileMode.Append);
            }
            catch
            {

            }
        }
    }
}
