记录系统日志方法

        private static void SaveLog(string log,string ex)
        {
            string strCurPath = AppDomain.CurrentDomain.BaseDirectory;
            string strErrorLogPath = Path.Combine(strCurPath, "ErrorLog");
            string strErrorLogFile = Path.Combine(strErrorLogPath, "SendEmailLog.log");
            if (!Directory.Exists(strErrorLogPath))
            {
                Directory.CreateDirectory(strErrorLogPath);
            }
            var fs = new FileStream(strErrorLogFile, FileMode.OpenOrCreate);
            var streamWriter = new StreamWriter(fs);
            streamWriter.BaseStream.Seek(0, SeekOrigin.End);
            streamWriter.WriteLine("系统记录时间:[" + DateTime.Now + "]");
            streamWriter.WriteLine("事件 :"+log);
            streamWriter.WriteLine("错误日志:"+ex);
            streamWriter.WriteLine("");
            streamWriter.Flush();
            streamWriter.Close();
            fs.Close();
        }

posted @ 2012-08-30 08:49  Tauren  阅读(242)  评论(0编辑  收藏  举报