using Microsoft.VisualBasic.CompilerServices;
using System;
using System.IO;

//namespace SE0085.CTdB
namespace FAS_LIB
{
    public class clsLogWriter
    {
        private StreamWriter _LogWrt;

        public clsLogWriter(string LogFile)
        {
            try
            {
                this._LogWrt = new StreamWriter(LogFile, true);
                this._LogWrt.Write("\r\nLog Entry : " + DateTime.Now.ToString() + "\r\n");
            }
            catch (Exception ex)
            {
                ProjectData.SetProjectError(ex);
                ProjectData.ClearProjectError();
            }
        }

        ~clsLogWriter()
        {
            try
            {
                this.logClose();
            }
            catch (Exception ex)
            {
                ProjectData.SetProjectError(ex);
                ProjectData.ClearProjectError();
            }
            // ISSUE: explicit finalizer call
            //base.Finalize();
        }

        public void logData(string logMessage)
        {
            try
            {
                this._LogWrt.Write("{0} {1}", (object)DateTime.Now.ToLongTimeString(), (object)DateTime.Now.ToLongDateString());
                this._LogWrt.WriteLine("  :{0}", (object)logMessage);
                this._LogWrt.Flush();
                Console.Write("{0} {1}", (object)DateTime.Now.ToLongTimeString(), (object)DateTime.Now.ToLongDateString());
                Console.WriteLine("  :{0}", (object)logMessage);
            }
            catch (Exception ex)
            {
                ProjectData.SetProjectError(ex);
                ProjectData.ClearProjectError();
            }
        }

        public void logDataEOL()
        {
            try
            {
                this._LogWrt.WriteLine("EOL------------------ {0} {1} ------------------EOL", (object)DateTime.Now.ToLongTimeString(), (object)DateTime.Now.ToLongDateString());
                this._LogWrt.Flush();
            }
            catch (Exception ex)
            {
                ProjectData.SetProjectError(ex);
                ProjectData.ClearProjectError();
            }
        }

        public void logClose()
        {
            try
            {
                this._LogWrt.Flush();
                this._LogWrt.Close();
                this._LogWrt.Dispose();
                this._LogWrt = (StreamWriter)null;
            }
            catch (Exception ex)
            {
                ProjectData.SetProjectError(ex);
                ProjectData.ClearProjectError();
            }
        }
    }
}
