using System; using System.Web; using Curtain.DataAccess; /// /// PLC执行日志 xuwei modify 2020-07-14 简化webapi方法 /// public class ApiLog { /// /// 接口类型 /// public enum ApiType { /// /// WebApi /// WebApi, /// /// WebService /// WebService } /// /// 接口请求方式 /// public enum ApiRuquest { /// /// Get方式 /// Get, /// /// Post方式 /// Post } /// /// PLC执行操作写入日志 /// /// 接口名称 /// 接口类型 /// 接口请求方式 /// 接口地址 /// 接口方法名(用于WEBSERVICE) /// 接口请求参数JSON格式 /// 接口请求状态 /// 接口请求结果 /// 接口ID用于统计 /// 条码数量用于统计 public static void WriteApiLog(string name, ApiType type, ApiRuquest request, string url, string method, string parameter, bool status, string result, int apiid = 0, int barcodecount = 1) { try { if (HttpContext.Current.Request.Url.Host.ToLower() == HttpContext.Current.Request.UserHostAddress.ToLower()) { return; } using (IDataAccess conn = DataAccess.Create()) { string sqlString = @" INSERT INTO TP_MST_APILOG (APIID ,NAME ,TYPE ,REQUEST ,URL ,METHOD ,PARAMETER ,STATUS ,RESULT ,BARCODECOUNT ,GUESTIP ,GUESTHOST) VALUES (@APIID@ ,@NAME@ ,@TYPE@ ,@REQUEST@ ,@URL@ ,@METHOD@ ,@PARAMETER@ ,@STATUS@ ,@RESULT@ ,@BARCODECOUNT@ ,@GUESTIP@ ,@GUESTHOST@)"; CDAParameter[] paras = new CDAParameter[] { new CDAParameter("APIID", apiid), new CDAParameter("NAME", name), new CDAParameter("TYPE", type.ToString()), new CDAParameter("REQUEST", request.ToString()), new CDAParameter("URL", url), new CDAParameter("METHOD", method), new CDAParameter("PARAMETER", parameter), new CDAParameter("STATUS", status ? '1' : '0'), new CDAParameter("RESULT", result), new CDAParameter("BARCODECOUNT", barcodecount), new CDAParameter("GUESTIP", HttpContext.Current.Request.UserHostAddress), new CDAParameter("GUESTHOST", HttpContext.Current.Request.UserHostName), }; conn.BeginTransaction(); conn.ExecuteNonQuery(sqlString, paras); conn.Commit(); } } catch (Exception ex) { throw ex; } } /// /// 简化的webapi写日志方法 /// /// /// /// /// /// public static void WriteApiLog(string name, string url, bool status, string result, int apiid = 0, int barcodecount = 1) { WriteApiLog(name, ApiType.WebApi, ApiRuquest.Get, url, "", "", status, result, apiid, barcodecount); } }