标签:style blog io ar color os sp on div
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; } }
标签:style blog io ar color os sp on div
原文地址:http://www.cnblogs.com/jianmo/p/4128360.html