using System;
using System.IO;
using System.Text;

namespace QMAPP.WinForm
{
    public static class LogHelper
    {
        public static readonly string LogPath = $"{IoHelper.GetDllPath()}//Logs";

        public static void Write(string content, string path = null)
        {
            try
            {
                if (path == null)
                    path = LogPath;
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                string filename = $"{path}//{DateTime.Now:yyyyMMdd}.log";
                StreamWriter sw = new StreamWriter(filename, true, Encoding.Unicode);
                sw.WriteLine($"{DateTime.Now:HH:mm:ss fff}\t{content}");
                sw.WriteLine($"-----------------------------------------{Environment.NewLine}");
                sw.Close();
            }
            catch (Exception)
            {
                //                MessageBox.Show(ex.ToString());
            }
        }

        public static void WriteEx(Exception ex)
        {
            Write(ex.ToString());
        }

        public static void WriteEx(Exception ex, string path)
        {
            Write(ex.ToString(), path);
        }
    }
}