示例#1
0
文件: LogBll.cs 项目: gofixiao/SCM
 /// <summary>
 /// 数据库无法写日志,写本地文件
 /// </summary>
 /// <param name="log"></param>
 private static void Write(CLog log)
 {
     var filename =string.Format("{0}/Logs/log{1}.txt", HttpContext.Current.Server.MapPath("/"), DateTime.Now.ToString("yyMMdd"));
     if (!Directory.Exists(string.Format("{0}/Logs", HttpContext.Current.Server.MapPath("/"))))
     {
         Directory.CreateDirectory(string.Format("{0}/Logs", HttpContext.Current.Server.MapPath("/")));
     }
     var fs = !File.Exists(filename) ? new FileStream(filename, FileMode.CreateNew) : new FileStream(filename,FileMode.Append);
     var logText = Encoding.Default.GetBytes(string.Format("时间:{0}#操作人:{1}#结果:{2}#内容:{3}#\r\n",
        DateTime.Now.ToString("yyyy-MM-dd HH:m:s.fff"),
         log.LogUser.Trim(),
         log.LogType,
         log.LogContent.Trim())
     );
     fs.Write(logText,0,logText.Length);
     fs.Close();
 }
示例#2
0
文件: LogBll.cs 项目: gofixiao/SCM
 public static void Write(IDal dal, CLog log)
 {
     try
     {
         if (dal.IsOpen)
         {
             int i;
             dal.Execute(
                 "INSERT INTO dbo.tXtLog( LogDate, LogContent, LogType,LogUser )VALUES  ( GETDATE(),@LogContent,@LogType,@LogUser)",
                 out i,
                 dal.CreateParameter("@LogContent", log.LogContent.Trim()),
                 dal.CreateParameter("@LogType", log.LogType),
                 dal.CreateParameter("@LogUser", log.LogUser.Trim()));
         }
         else
         {
             Write(log);
         }
     }
     catch
     {
         Write(log);
     }
 }