using FangYar.BLL.TBL; using FangYar.Common; using FangYar.Model.TBL; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Web; namespace FangYar.WebUI.WebCommon { ///// ///// 系统操作记录添加到系统日志 ///// //public class SysOperationLogHelp //{ // /// // /// 系统日志记录 // /// // private static SysOperationLogBLL syslogBll = new SysOperationLogBLL(); // /// // /// 设置是否记录操作日志:0、记录;其他、不记录 // /// // public static string IsOperationLogDebug = System.Configuration.ConfigurationManager.AppSettings["IsOperationLogDebug"] + ""; // /// // /// 用户操作日志记录 // /// // /// 请求信息HttpContext对象 // /// 日志类型 // /// 信息名称 // /// 信息内容 // public static void AddSysOperationLog(HttpContext context, EnumOperationLogType logType, string Info_Name, string Info_Msg) // { // if (!IsOperationLogDebug.Equals("0")) // { // return; // } // //new Thread(() => // //{ // try // { // //Tbl_Sys_Operation_Log_Model addMo = GetLogMoByHttpContext(HttpContext.Current); // Tbl_Sys_Operation_Log_Model addMo = GetLogMoByHttpContext(context); // addMo.Info_Type = ((int)logType) + ""; // addMo.Info_Msg = Info_Msg; // addMo.Info_Name = Info_Name; // if (string.IsNullOrWhiteSpace(addMo.Url_Str)) // { // string a = ""; // } // syslogBll.Add(addMo); // //添加到ClickHouse数据库 // //ClickHouseHelper.AddSysOperationLog(addMo); // } // catch (Exception ex) // { // string str = "系统日志记录异常:" + ex; // FangYar.Common.MyLogHelper.WriteMsg(new FangYar.Common.LogInfoMo() // { // message = str, // msgType = FangYar.Common.EnumLogMsgTypeEnum.Error, // path = "SysOperationLog" // }); // } // //}).Start(); // } // private static Tbl_Sys_Operation_Log_Model GetLogMoByHttpContext(HttpContext context) // { // Tbl_Sys_Operation_Log_Model retMo = new Tbl_Sys_Operation_Log_Model(); // try // { // var Request = context.Request; // var cookUserMo = GetCookUserByHttpContext(context); // retMo = new Tbl_Sys_Operation_Log_Model(); // retMo.ID = ""; // retMo.Info_Msg = ""; // retMo.Info_Name = ""; // retMo.createtime = ""; // retMo.Info_Type = null; // try // { // retMo.Url_Form = GetFormStr(context); // } // catch (Exception ex) // { // string str = "系统日志记录HttpContext获取Form参数信息异常:" + ex; // FangYar.Common.MyLogHelper.WriteMsg(new FangYar.Common.LogInfoMo() { message = str, msgType = FangYar.Common.EnumLogMsgTypeEnum.Error, path = "SysOperationLog" }); // } // try // { // retMo.User_Uid = cookUserMo.usersUid; // } // catch (Exception ex) // { // string str = "系统日志记录HttpContext获取登录用户账号异常:" + ex; // FangYar.Common.MyLogHelper.WriteMsg(new FangYar.Common.LogInfoMo() { message = str, msgType = FangYar.Common.EnumLogMsgTypeEnum.Error, path = "SysOperationLog" }); // } // try // { // retMo.Browser = Request.Browser.Browser; // retMo.Browser_Type = Request.Browser.Type; // retMo.System_Type = Request.Browser.Platform; // retMo.Browser_VerSion = Request.Browser.Version; // } // catch (Exception ex) // { // string str = "系统日志记录HttpContext获取客户端浏览器异常:" + ex; // FangYar.Common.MyLogHelper.WriteMsg(new FangYar.Common.LogInfoMo() { message = str, msgType = FangYar.Common.EnumLogMsgTypeEnum.Error, path = "SysOperationLog" }); // } // //获取用户IC // retMo.Client_IP = GetClientIp(context); // //获取用户端UUID // retMo.UUID_Str = GetUUID(context); // try // { // retMo.Client_Name = Request.UserHostName; // } // catch (Exception ex) // { // string str = "系统日志记录HttpContext获取用户IP信息异常:" + ex; // FangYar.Common.MyLogHelper.WriteMsg(new FangYar.Common.LogInfoMo() { message = str, msgType = FangYar.Common.EnumLogMsgTypeEnum.Error, path = "SysOperationLog" }); // } // try // { // retMo.Url_Str = Request.Url.AbsoluteUri; // } // catch (Exception ex) // { // string str = "系统日志记录HttpContext获取请求路径信息异常:" + ex; // FangYar.Common.MyLogHelper.WriteMsg(new FangYar.Common.LogInfoMo() // { // message = str, // msgType = FangYar.Common.EnumLogMsgTypeEnum.Error, // path = "SysOperationLog" // }); // } // string Headers_Str = Request.ServerVariables["All_Http"]; // string Headers_StrHead = Headers_Str.Substring(0, Headers_Str.IndexOf(".SessionCookie=")); // string Headers_StrEnd = Headers_Str.Substring(Headers_Str.IndexOf("HTTP_HOST:")); // Headers_Str = Headers_StrHead + Headers_StrEnd; // retMo.Headers_Str = Headers_Str; // string Headers_Str1 = Request.ServerVariables["All_Raw"]; // string Headers_Str1Head = Headers_Str1.Substring(0, Headers_Str1.IndexOf(".SessionCookie")); // string Headers_Str1End = Headers_Str1.Substring(Headers_Str1.IndexOf("Host:")); // Headers_Str1 = Headers_Str1Head + Headers_Str1End; // retMo.Headers_Str1 = Headers_Str1; // retMo.Action_Str = context.Request.Params["Action"] + ""; // retMo.Url_Parameter = Request.Url.Query; // retMo.Browser_System_Str = Request.ServerVariables["HTTP_USER_AGENT"]; // retMo.Org_ID = cookUserMo.orgId; // retMo.Org_Name = cookUserMo.orgName; // retMo.roles = cookUserMo.roles; // retMo.UserMobile = cookUserMo.userMobile; // retMo.User_Name = cookUserMo.usersName; // retMo.Post_Parameter = GetPostParam(Request); // } // catch (Exception ex) // { // string str = "系统日志记录HttpContext转换异常:" + ex; // FangYar.Common.MyLogHelper.WriteMsg(new FangYar.Common.LogInfoMo() // { // message = str, // msgType = FangYar.Common.EnumLogMsgTypeEnum.Error, // path = "SysOperationLog" // }); // } // return retMo; // } // private static string GetPostParam(HttpRequest Request) // { // string postParam = ""; //post的所有参数 // try // { // using (System.IO.StreamReader sr = new System.IO.StreamReader(Request.InputStream)) // { // postParam = sr.ReadLine(); // } // } // catch (Exception ex) // { // string str = "系统日志记录获取Post参数异常:" + ex; // FangYar.Common.MyLogHelper.WriteMsg(new FangYar.Common.LogInfoMo() // { // message = str, // msgType = FangYar.Common.EnumLogMsgTypeEnum.Error, // path = "SysOperationLog" // }); // } // return postParam; // } // /// // /// 返回客户端IP // /// // /// // /// // private static string GetClientIp(HttpContext context) // { // string retStr = ""; // try // { // string ipStr = context.Request.ServerVariables["All_Http"]; // if (ipStr.IndexOf("HTTP_X_CLIENT_IP:") < 0) // { // return "未获取"; // } // ipStr = ipStr.Substring(ipStr.IndexOf("HTTP_X_CLIENT_IP:") + 17); // retStr = ipStr.Substring(0, ipStr.IndexOf("HTTP_")); // } // catch (Exception ex) // { // string str = "系统日志记录HttpContext获取用户IP信息异常:" + ex; // FangYar.Common.MyLogHelper.WriteMsg(new FangYar.Common.LogInfoMo() { message = str, msgType = FangYar.Common.EnumLogMsgTypeEnum.Error, path = "SysOperationLog" }); // } // return retStr; // } // /// // /// 返回客户端UUID // /// // /// // /// // private static string GetUUID(HttpContext context) // { // string retStr = ""; // try // { // string ipStr = context.Request.ServerVariables["All_Http"]; // if (ipStr.IndexOf("HTTP_X5_UUID:") < 0) // { // return "未获取"; // } // retStr = ipStr.Substring(ipStr.IndexOf("HTTP_X5_UUID:") + 13); // } // catch (Exception ex) // { // string str = "系统日志记录HttpContext获取客户端UUID异常:" + ex; // FangYar.Common.MyLogHelper.WriteMsg(new FangYar.Common.LogInfoMo() { message = str, msgType = FangYar.Common.EnumLogMsgTypeEnum.Error, path = "SysOperationLog" }); // } // return retStr; // } // /// // /// 获取Cook缓存信息 // /// // /// // /// // private static CookUserMo GetCookUserByHttpContext(HttpContext context) // { // CookUserMo retMo = new CookUserMo(); // try // { // //if (context.Request.Cookies["kn_root_cookie"] == null) // //{ // // return new CookUserMo() { cityId = "", deptId = "", deptName = "", orgId = "", orgName = "", roles = "", userMobile = "", usersName = "", usersUid = "" }; // //} // //string CookStr = context.Request.Cookies["kn_root_cookie"].Value + ""; // string CookStr = context.Request.ServerVariables["All_Http"]; // if (CookStr.IndexOf("kn_root_cookie=") < 0) // { // return new CookUserMo() { cityId = "", deptId = "", deptName = "", orgId = "", orgName = "", roles = "", userMobile = "", usersName = "", usersUid = "" }; // } // CookStr = CookStr.Substring(CookStr.IndexOf("kn_root_cookie=") + 15); // CookStr = CookStr.Substring(0, CookStr.IndexOf("}") + 1); // //CookStr = CookStr.Replace("kn_root_cookie=", ""); // retMo = JsonHelper.FromJSON(CookStr); // } // catch (Exception ex) // { // retMo = new CookUserMo() { cityId = "", deptId = "", deptName = "", orgId = "", orgName = "", roles = "", userMobile = "", usersName = "", usersUid = "" }; // string str = "系统日志记录获取Cook信息异常:" + ex; // FangYar.Common.MyLogHelper.WriteMsg(new FangYar.Common.LogInfoMo() // { // message = str, // msgType = FangYar.Common.EnumLogMsgTypeEnum.Error, // path = "SysOperationLog" // }); // } // return retMo; // } // private static string GetFormStr(HttpContext context) // { // string retStr = ""; // try // { // foreach (var item in context.Request.Params) // { // if (item.Equals(".SessionCookie")) // { // continue; // } // if (item.Equals("ALL_HTTP")) // { // continue; // } // if (item.Equals("ALL_RAW")) // { // continue; // } // if (item.Equals("HTTP_COOKIE")) // { // continue; // } // if (item.Equals("ASP.NET_SessionId")) // { // continue; // } // string a = ""; // if (!string.IsNullOrWhiteSpace(retStr)) // { // retStr += "&"; // } // // retStr += item + "=" + GetParams(context.Request.Params[item + ""] + ""); // retStr += item + "=" + context.Request.Params[item + ""]; // } // } // catch (Exception ex) // { // string str = "系统日志记录后去Form参数异常:" + ex; // FangYar.Common.MyLogHelper.WriteMsg(new FangYar.Common.LogInfoMo() // { // message = str, // msgType = FangYar.Common.EnumLogMsgTypeEnum.Error, // path = "SysOperationLog" // }); // } // return retStr; // } // //private static string GetParams(string str) // //{ // // string retStr = ""; // // try // // { // // // retStr = HttpContext.Current.Server.UrlDecode(str); // // retStr = str; // // } // // catch (Exception e) // // { // // } // // return retStr; // //} //} }