C#开发之简单的日志打印类

简单的日志打印的帮助类,以后会继续补充更多的逻辑

public  class LogHelper
    {
        private static readonly LogHelper Instance = new LogHelper();
        public static LogHelper GetLogHelper()
        {
            return Instance;
        }

        #region 公共属性
        public string StrStartupPath
        {
            get { return Environment.CurrentDirectory; }
        }
        public string FileName
        {
            get
            {
                return StrStartupPath + @"\Logs" + @"\SyncLog" + DateTime.Now.ToString("yyyyMMdd") + ".txt";
            }
        }

        #endregion

        #region 写日志

        public void CreateLog(string strMsg)
        {

            //1. 判断目录是否存在
            var fileLocation = StrStartupPath + @"\Logs";
            if (!Directory.Exists(fileLocation))
            {
                Directory.CreateDirectory(fileLocation);
            }

            //2. 日志写入
            using (StreamWriter myWriter = new StreamWriter(FileName, true))
            {
                try
                {
                    myWriter.WriteLine("============" + DateTime.Now.ToString("yy/MM/dd HH:mm:ss:fff") + "," + strMsg +
                                       "============");
                    myWriter.WriteLine("");
                }
                finally
                {
                    myWriter.Close();
                }
            }

        }
        #endregion

    }