using System;
using System.IO;

namespace FindUUPass
{
    class LogHelper
    {
        #region  创建日志
        public static void WriteLog(string message)
        {
            string strPath;                                                   //文件的路径
            DateTime dt = DateTime.Now;
            try
            {
                strPath = Directory.GetCurrentDirectory() + "Logs";         //创建日志文件夹 

                if (Directory.Exists(strPath) == false)                       //工程目录下 Logs目录 '目录是否存在,为true则没有此目录
                {
                    Directory.CreateDirectory(strPath);                       //建立目录 Directory为目录对象
                }
                strPath = strPath + "" + dt.ToString("yyyy");

                if (Directory.Exists(strPath) == false)
                {
                    Directory.CreateDirectory(strPath);
                }
                strPath = strPath + "" + dt.ToString("yyyy-MM-dd") + ".txt";

                StreamWriter FileWriter = new StreamWriter(strPath, true);           //创建日志文件
                FileWriter.WriteLine("[" + dt.ToString("yyyy-MM-dd HH:mm:ss") + "] : " + message);
                FileWriter.Close();                                                 //关闭StreamWriter对象
            }
            catch (Exception ex)
            {
                string str = ex.Message.ToString();
            }
        }
        #endregion
    }
}
public static void LogWrite(string LogText) 
{ 
         LogHelper.WriteLog(LogText); 
         Console.WriteLine(DateTime.Now.ToString("[yyyy-MM-dd HH:mm:ss] : ") + LogText); 
}