首页 > 代码库 > 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
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。