首页 > 代码库 > lOG

lOG

 public class WriteLog    {        public void WritelogDetail(string type, string Content)        {            try            {                string directory = System.AppDomain.CurrentDomain.BaseDirectory + "LogFile\\";                string filePath = directory + type + "_" + Guid.NewGuid().ToString() + ".txt";                if (!Directory.Exists(directory))                {                    Directory.CreateDirectory(directory);                }                if (!File.Exists(filePath))                {                    FileStream fs = File.Create(filePath);                    fs.Close();                }                               using (StreamWriter sw = new StreamWriter(filePath))                {                    sw.WriteLine("--------System Log-----------");                    sw.WriteLine(Environment.NewLine);                    sw.Write(Content + Environment.NewLine);                    sw.WriteLine("-------------------");                    sw.WriteLine(DateTime.Now);                                              }            }            catch(Exception e)            {            }        }        public void WritelogDetailDal(string type, string Content)        {            try            {                string directory = System.AppDomain.CurrentDomain.BaseDirectory + "LogFile\\DalLog\\";                string filePath = directory + type + "_" + Guid.NewGuid().ToString() + ".txt";                if (!Directory.Exists(directory))                {                    Directory.CreateDirectory(directory);                }                if (!File.Exists(filePath))                {                    FileStream fs = File.Create(filePath);                    fs.Close();                }                using (StreamWriter sw = new StreamWriter(filePath))                {                    sw.WriteLine("--------System Log-----------");                    sw.Write(Content + Environment.NewLine);                    sw.WriteLine("-------------------");                    sw.WriteLine(DateTime.Now);                }            }            catch (Exception e)            {            }        }        public string DateDiff(DateTime dtStart, DateTime dtEnd)        {            string dateDiff = null;            try            {                TimeSpan ts1 = new TimeSpan(dtEnd.Ticks);                TimeSpan ts2 = new TimeSpan(dtStart.Ticks);                TimeSpan ts = ts1.Subtract(ts2).Duration();                dateDiff = ts.Days.ToString() + ""                        + ts.Hours.ToString() + "小时"                        + ts.Minutes.ToString() + "分钟"                        + ts.Seconds.ToString() + ""                        + ts.Milliseconds.ToString() + "毫秒";            }            catch            {            }            return dateDiff;        }    }

 

lOG