protected static void Log(bool save, string action, object id, object data, Type type) { if (!save) { return; } string json = Jsonlizer.ToJson(data, 20, true, true); // 序列化为json,并跳过复杂的属性 string txt = string.Format("{0}: ID={1}, Type={2}, Data={3}", action, id, type, json); UtilConfig.Log("Database", txt); }
// 日志 private static void Log <T>(DbCommand command, DbCommandInterceptionContext <T> interceptionContext) { var duration = Stop(command); var txt = string.Format("{0}\r\n耗时:{1} ms", command.GetCommandText(), duration.TotalMilliseconds); if (duration.TotalSeconds > 1 || interceptionContext.Exception != null) { // 异常日志 txt = string.Format("数据库异常:{0} \r\n{1} ", txt, interceptionContext.Exception?.Message); UtilConfig.Log("Database", txt, 1); // 注意不能存储在数据库中,会造成无限递归错误 } else { // 普通日志 //Logger.Log(txt); } }
/// <summary>处理文件资源</summary> public void HandleFileRes(string url) { // 文件扩展名及推断属性 this.FileExtension = url.GetFileExtension(); this.MimeType = IO.GetMimeType(this.FileExtension); this.Type = this.MimeType.Contains("image") ? ResType.Image : ResType.File; // 物理文件属性 if (url.IsSiteFile()) { try { var physicalPath = Asp.MapPath(url); var fi = new FileInfo(physicalPath); this.FileSize = fi.Length; this.FileMD5 = IO.GetFileMD5(physicalPath); } catch (Exception e) { UtilConfig.Log("GetFileInfoFail", e.Message); }; } }