首页 > 代码库 > c#写日志方法
c#写日志方法
//日志内容,文件名private string writelog(string value,string name ) { string strPath = ""; try { strPath = System.Web.HttpContext.Current.Server.MapPath("log"); } catch { } if (strPath == "") strPath = Application.StartupPath; FileStream logFile = null; string strDate = DateTime.Now.Year.ToString(); strDate += "-"+DateTime.Now.Month.ToString(); strDate += "-" + DateTime.Now.Day.ToString(); if (!Directory.Exists(strPath+"\\log")) Directory.CreateDirectory(strPath+"\\log"); if (!Directory.Exists(strPath + "\\log\\" + strDate)) Directory.CreateDirectory(strPath + "\\log\\" + strDate); strPath = strPath + "\\log\\" + strDate + "\\" + name + ".txt"; if (logFile == null) logFile = new FileStream(strPath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite); string strLine=Environment.NewLine; string strTime=DateTime.Now.ToString("HH:mm:ss"); string str = ""; if (name != "upbeifensql" && name != "upedsql" && name != "lianjisql") str = strTime + strLine; str += value + strLine; if (name != "upbeifensql" && name != "upedsql" && name != "lianjisql") str += "*****************************************************************************************************************************" + strLine; if (name == "upbeifensql" || name == "upedsql" || name == "lianjisql") { CompressionHelper compress = new CompressionHelper(); str = compress.CompressToString(str); str += strLine; } byte[] bytes = System.Text.Encoding.Default.GetBytes(str); logFile.Position = logFile.Length; logFile.Write(bytes, 0, (int)bytes.Length); logFile.Close(); logFile = null; return strPath; }
c#写日志方法
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。