You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
Gdsi-Api/Gdsi/Helper/LogHelper.cs

98 lines
3.4 KiB

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请求(包含调用时间)
/// <summary>
/// HIS请求
/// </summary>
/// <param name="method">HIS方法</param>
/// <param name="req">json入参</param>
/// <param name="resp">json出参</param>
/// <param name="resp">调用开始时间</param>
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 方法异常
/// <summary>
/// 方法异常
/// </summary>
/// <param name="ee"></param>
/// <param name="method"></param>
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
}
}