using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Gdsi.Helper { public class LogHelper { #region HIS请求(包含调用时间) /// /// HIS请求 /// /// HIS方法 /// json入参 /// json出参 /// 调用开始时间 public static void doJsonRequestLog(string method, string req, string resp, DateTime stime) { string path = "D:\\FangDing\\FountainLog\\HisZY\\" + "Josn"; try { //if (!Directory.Exists(path)) //{ // Directory.CreateDirectory(path); //} FileStream fs = new FileStream(path + "\\" + DateTime.Today.ToString("yyyyMMddHHmmss").Substring(0, 8).ToString() + ".txt", FileMode.Append, FileAccess.Write); StreamWriter sw = new StreamWriter(fs); sw.WriteLine("--------------------------------\r\n"); try { DateTime dnow = DateTime.Now; sw.WriteLine("调用时间:" + stime.ToString()); sw.WriteLine("返回时间:" + dnow.ToString()); TimeSpan span = dnow - stime; string hs = (span.TotalSeconds).ToString() + "秒"; sw.WriteLine("耗时:" + hs); } catch { } sw.WriteLine("方法:" + method); sw.WriteLine("入参:"); sw.WriteLine(req); sw.WriteLine("出参:"); sw.WriteLine(resp); sw.WriteLine("--------------------------------\r\n\r\n"); sw.Flush(); sw.Close(); fs.Close(); } catch (Exception ee) { LogHelper.getCatch(ee, method); } } #endregion #region 方法异常 /// /// 方法异常 /// /// /// public static void getCatch(Exception ee, string method) { string path = "D:\\FangDing\\FountainLog\\HisZY\\" + "Error"; try { //if (!Directory.Exists(path)) //{ // Directory.CreateDirectory(path); //} FileStream fs = new FileStream(path + "\\" + DateTime.Today.ToString("yyyyMMddHHmmss").Substring(0, 8).ToString() + ".txt", FileMode.Append, FileAccess.Write); StreamWriter sw = new StreamWriter(fs); sw.WriteLine("--------------------------------\r\n"); sw.WriteLine("时间:" + DateTime.Now.ToString()); sw.WriteLine("方法:" + method); sw.WriteLine("消息:" + ee.Message); sw.WriteLine("源:" + ee.Source); sw.WriteLine("数据:" + ee.Data); sw.WriteLine("--------------------------------\r\n\r\n"); sw.Flush(); sw.Close(); fs.Close(); } catch { } } #endregion } }