private static SysExceptionLog AttachException(SysExceptionLog log, System.Exception ex) { log.ExData = Dictionary2String(ex.Data); log.ExMessage = ex.Message; log.ExSource = ex.Source; log.ExStackTrace = ex.StackTrace; if (ex.TargetSite != null) { log.ExTargetSite = ex.TargetSite.ToString(); } if (ex.InnerException != null) { System.Exception innerEx = ex.InnerException; log.InnerData = Dictionary2String(innerEx.Data); log.InnerMessage = innerEx.Message; log.InnerSource = innerEx.Source; log.InnerStackTrace = innerEx.StackTrace; if (innerEx.TargetSite != null) { log.InnerTargetSite = innerEx.TargetSite.ToString(); } } log.LogTime = DateTime.Now; return(log); }
public static void Log(SysExceptionLog log) { string file_path = GetLogFile(); FileStream stream = new FileStream(file_path, FileMode.Append, FileAccess.Write, FileShare.ReadWrite); try { StreamWriter writer = new StreamWriter(stream, System.Text.Encoding.UTF8); writer.WriteLine(); writer.WriteLine(); writer.WriteLine(LogPrefix); writer.WriteLine(LogPrefix); writer.Write("date-time: "); writer.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); writer.Write("log-type: "); writer.WriteLine(log.LogType); writer.Write("user-id: "); writer.WriteLine(log.UserId); writer.Write("extra-message: "); writer.WriteLine(log.Description); writer.Write("error-url: "); writer.WriteLine(log.ErrorUrl); writer.Write("http-context: "); writer.WriteLine(log.HttpContext); writer.Write("ex-message: "); writer.WriteLine(log.ExMessage); writer.Write("ex-data: "); writer.WriteLine(log.ExData); writer.Write("ex-source: "); writer.WriteLine(log.ExSource); writer.Write("ex-stack-trace: "); writer.WriteLine(log.ExStackTrace); writer.Write("ex-target-site: "); writer.WriteLine(log.ExTargetSite); writer.Write("inner-message: "); writer.WriteLine(log.InnerMessage); writer.Write("inner-data: "); writer.WriteLine(log.InnerData); writer.Write("inner-source: "); writer.WriteLine(log.InnerSource); writer.Write("inner-stack-trace: "); writer.WriteLine(log.InnerStackTrace); writer.Write("inner-target-site: "); writer.WriteLine(log.InnerTargetSite); writer.Flush(); stream.Flush(); writer.Close(); } catch { } finally { stream.Close(); } }
public static void WriteLog(string log_type, Exception ex) { SysExceptionLog log = new SysExceptionLog(); log.LogType = log_type; AttachException(log, ex); log.LogId = System.Guid.NewGuid().ToString("D").ToUpper(); log.LogTime = DateTime.Now; AttachException(log, ex); WriteLog(log); }
private static void WriteLog(SysExceptionLog log) { FileSystemLog.Log(log); }