public static void WriteServiceLog(string logType, string message, string menu, string result, LogOpration logOpration = LogOpration.Default) { try { //logOpration设置优先级高于配置节logEnabled bool logEnabled = Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["LogEnabled"]); if (logOpration == LogOpration.Fobid || (logOpration == LogOpration.Default && !logEnabled)) { return; } else if (logOpration == LogOpration.Start || (logOpration == LogOpration.Default && logEnabled)) { SysLog sysLog = new SysLog(); sysLog.CreateTime = DateTime.Now; sysLog.Ip = GetIP(); sysLog.Message = message; if (HttpContext.Current != null && HttpContext.Current.Session["account"] != null) { Account account = (Account)HttpContext.Current.Session["account"]; if (account != null && !string.IsNullOrWhiteSpace(account.PersonName)) { sysLog.PersonId = account.PersonName; } } else { sysLog.PersonId = "未登录用户"; } sysLog.State = logType; sysLog.Result = result; sysLog.MenuId = menu; sysLog.Id = Result.GetNewId(); using (SysLogBLL sysLogRepository = new SysLogBLL()) { ValidationErrors validationErrors = new ValidationErrors(); sysLogRepository.Create(ref validationErrors, sysLog); return; } } } catch (Exception ep) { try { string path = @"~/mylog.txt"; string txtPath = System.Web.HttpContext.Current.Server.MapPath(path);//获取绝对路径 using (StreamWriter sw = new StreamWriter(txtPath, true, Encoding.Default)) { sw.WriteLine((ep.Message + "|" + logType + "|" + message + "|" + "MySession.Get(MySessionKey.UserID)" + "|" + GetIP() + DateTime.Now.ToString()).ToString()); sw.Close(); } return; } catch { return; } } }
public static void WriteServiceLog(string message, string logType, LogOpration logOpration = LogOpration.Default) { try { //logOpration设置优先级高于配置节logEnabled bool logEnabled = Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["LogEnabled"]); if (logOpration == LogOpration.Fobid || (logOpration == LogOpration.Default && !logEnabled)) { return; } else if (logOpration == LogOpration.Start || (logOpration == LogOpration.Default && logEnabled)) { //此处实现日志的记录 SysLog sysLog = new SysLog(); sysLog.Id = Result.GetNewId(); sysLog.CreateTime = DateTime.Now; sysLog.Ip = GetIP(); sysLog.Message = message; sysLog.CreatePerson = AccountModel.GetCurrentPerson(); sysLog.MenuId = logType;//哪个模块生成的日志 using (var sysLogRepository = new SysLogBLL()) { ValidationErrors validationErrors = new ValidationErrors(); sysLogRepository.Create(ref validationErrors, sysLog); return; } } } catch (Exception ep) { try { string path = @"/up/mylog.txt"; string txtPath = System.Web.HttpContext.Current.Server.MapPath(path);//获取绝对路径 using (StreamWriter sw = new StreamWriter(txtPath, true, Encoding.Default)) { sw.WriteLine((ep.Message + "|" + message + "|" + GetIP() + DateTime.Now.ToString()).ToString()); sw.Close(); } return; } catch { return; } } }
public SysLogController(SysLogBLL bll) { m_BLL = bll; }