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

namespace Common
{
    public class FileWriter
    {
        private static object LOCKOBJ = new object();
        private static object obj_lock = new object();

        private static string FILEPATH = "";

        static FileWriter()
        {
            FILEPATH = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "Logs\\";
            Console.Write(FILEPATH);
            if (Directory.Exists(FILEPATH) == false)
            {
                Directory.CreateDirectory(FILEPATH);
            }
        }

        public static void WriteLog(string text)
        {
            lock (LOCKOBJ)
            {
                try
                {
                    string file = FILEPATH + DateTime.Now.ToString("yyyyMMdd") + ".txt";
                    File.AppendAllText(file, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "：" + text + System.Environment.NewLine);
                }
                catch
                {
                }
            }
        }

        public static void Write_ERR_Log(string text)
        {
            lock (obj_lock)
            {
                try
                {
                    string file = FILEPATH + DateTime.Now.ToString("yyyyMMdd") + "_err.txt";
                    File.AppendAllText(file, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "：" + text + System.Environment.NewLine);
                }
                catch
                {
                }
            }
        }
    }
}
