| | |
| | | using Microsoft.AspNetCore.Http; |
| | | using Microsoft.OpenApi.Models; |
| | | using SqlSugar; |
| | | using StackExchange.Profiling.Internal; |
| | | using System; |
| | | using System.Collections.Concurrent; |
| | | using System.Collections.Generic; |
| | | using System.ComponentModel; |
| | | using System.Data; |
| | | using System.IO; |
| | | using System.Linq; |
| | | using System.Reflection; |
| | | using System.Runtime.Serialization.Formatters; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using System.Xml.Linq; |
| | | using WIDESEA_Core.DB; |
| | | using WIDESEA_Core.Enums; |
| | | using WIDESEA_Core.Helper; |
| | | using WIDESEA_Core.HttpContextUser; |
| | | using WIDESEA_Core.Seed; |
| | |
| | | row["RequestParam"] = log.RequestParam?.Replace("\r\n", "").Replace("\n", ""); |
| | | // å°ResponseParamä¸çæ¢è¡ç¬¦æ¿æ¢ä¸ºç©ºå符串 |
| | | row["ResponseParam"] = log.ResponseParam?.Replace("\r\n", "").Replace("\n", ""); |
| | | //row["Success"] = log.Success ?? -1; |
| | | row["Success"] = log.Success ?? -1; |
| | | // å°BeginDate设置为logçBeginDate |
| | | row["BeginDate"] = log.BeginDate; |
| | | // å°EndDate设置为logçEndDate |
| | |
| | | row["UserId"] = log.UserId ?? -1; |
| | | // å°UserName设置为logçUserName |
| | | row["UserName"] = log.UserName; |
| | | row["MethodName"] = log.MethodName; |
| | | row["Methodremark"] = log.Methodremark; |
| | | // å°rowæ·»å å°queueTableä¸ |
| | | queueTable.Rows.Add(row); |
| | | } |
| | |
| | | queueTable.Columns.Add("EndDate", Type.GetType("System.DateTime")); |
| | | queueTable.Columns.Add("RequestParam", typeof(string)); |
| | | queueTable.Columns.Add("ResponseParam", typeof(string)); |
| | | //queueTable.Columns.Add("Success", Type.GetType("System.Int32")); |
| | | queueTable.Columns.Add("Success", Type.GetType("System.Int32")); |
| | | queueTable.Columns.Add("Url", typeof(string)); |
| | | queueTable.Columns.Add("UserIP", typeof(string)); |
| | | queueTable.Columns.Add("UserName", typeof(string)); |
| | | queueTable.Columns.Add("UserId", Type.GetType("System.Int32")); |
| | | //queueTable.Columns.Add("LogType", typeof(string)); |
| | | //queueTable.Columns.Add("ExceptionInfo", typeof(string)); |
| | | queueTable.Columns.Add("MethodName", typeof(string)); |
| | | queueTable.Columns.Add("Methodremark", typeof(string)); |
| | | //queueTable.Columns.Add("ServiceIP", typeof(string)); |
| | | //queueTable.Columns.Add("BrowserType", typeof(string)); |
| | | //queueTable.Columns.Add("Role_Id", Type.GetType("System.Int32")); |
| | |
| | | public static void Add(string requestParameter, string responseParameter) |
| | | { |
| | | dynamic log = null; |
| | | string MethodName = string.Empty; |
| | | string Methodremark = string.Empty; |
| | | try |
| | | { |
| | | //è·åå½åHttpContext |
| | |
| | | { |
| | | return; |
| | | } |
| | | |
| | | //å¦æè¯·æ±æ¹æ³ä¸ºOPTIONSï¼åè¿å |
| | | if (context.Request.Method == "OPTIONS") return; |
| | | //è·åRequestLogModelå®ä¾ |
| | | RequestLogModel logModel = (context.RequestServices.GetService(typeof(RequestLogModel)) as RequestLogModel) ?? new RequestLogModel { RequestDate = DateTime.Now }; |
| | | #region è·åæ¥å£æ³¨é |
| | | try |
| | | { |
| | | string path = context.Request.Path; |
| | | var names = path.Split('/'); |
| | | var basePath = AppContext.BaseDirectory + "WIDESEA_WMSServer"; |
| | | Assembly assembly = Assembly.LoadFrom(basePath); |
| | | List<Type> types = assembly.GetTypes().Where(x => x.Name.Contains(names[2] + "Controller")).ToList(); |
| | | if (types.Count > 0) |
| | | { |
| | | //MethodInfo methodInfo = types.First().GetMethod("login"); |
| | | MethodInfo methodInfo = types.First().GetMethods() |
| | | .FirstOrDefault(m => m.Name.Equals(names[3], StringComparison.OrdinalIgnoreCase)); |
| | | if (methodInfo != null) |
| | | { |
| | | MethodName = methodInfo.Name; |
| | | string xmlPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, methodInfo.DeclaringType.Assembly.GetName().Name + ".xml"); |
| | | //if (!File.Exists(xmlPath)) return "XML documentation file not found."; // æ£æ¥æä»¶æ¯å¦åå¨ |
| | | // å è½½XMLææ¡£å¹¶è§£ææè¦ä¿¡æ¯ |
| | | XDocument xdoc = XDocument.Load(xmlPath); |
| | | string membername = $"M:{methodInfo.DeclaringType.FullName}.{methodInfo.Name}"; |
| | | var member = xdoc.Descendants("member") |
| | | .FirstOrDefault(m => m.Attribute("name").Value.ToString().Contains(membername));// å®ä½å°æ¹æ³èç¹ |
| | | //.FirstOrDefault(m => m.Attribute("name")?.Value == $"M:{methodInfo.DeclaringType.FullName}.{methodInfo.Name}"); // å®ä½å°æ¹æ³èç¹ |
| | | //if (member == null) return "Member not found in XML documentation."; // æ£æ¥æ¹æ³æ¯å¦å¨XMLææ¡£ä¸æ¾å° |
| | | //var summary = member?.Element("summary")?.Value ?? "No summary provided."; // è·åæè¦ä¿¡æ¯æé»è®¤å¼ |
| | | Methodremark = member?.Element("summary")?.Value.Replace("\n", "").Replace(" ", "") ?? methodInfo.Name; // è·åæè¦ä¿¡æ¯æé»è®¤å¼ |
| | | } |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | |
| | | } |
| | | #endregion |
| | | //è·åå½åç¨æ· |
| | | IUser user = App.User; |
| | | //å建æ¥å¿å¯¹è±¡ |
| | |
| | | RequestParam = requestParameter, |
| | | //ååºåæ° |
| | | ResponseParam = responseParameter, |
| | | //æ¹æ³åç§° |
| | | MethodName = MethodName, |
| | | //æ¹æ³æè¿° |
| | | Methodremark= Methodremark, |
| | | //ååºç¶æ |
| | | Success = LogStatusEnum.Success.ObjToInt(), |
| | | //请æ±URL |
| | | Url = context.Request.Scheme + "://" + context.Request.Host + context.Request.PathBase + context.Request.Path, |
| | | //客æ·ç«¯IP |
| | |
| | | RequestParam = requestParameter, |
| | | //ååºåæ° |
| | | ResponseParam = responseParameter, |
| | | //æ¹æ³åç§° |
| | | MethodName = MethodName, |
| | | //æ¹æ³æè¿° |
| | | Methodremark = Methodremark, |
| | | //ååºç¶æ |
| | | Success = LogStatusEnum.Error.ObjToInt(), |
| | | }; |
| | | } |
| | | //æ·»å ç³»ç»æ¥å¿ |