Exemplo n.º 1
0
        /// <summary>
        /// 添加系统错误日志
        /// </summary>
        /// <param name="context">页面的context</param>
        public void Save(System.Web.HttpContext context)
        {
            try
            {
                //收集服务器端页面发生的异常,并添加到数据库中
                var ex = context.Server.GetLastError().GetBaseException();

                var errorLog = new ErrorLog();
                //异常产生时间
                errorLog.ErrTime = DateTime.Now;

                var ch = new ClientHelper(context.Request);
                //客户端浏览器版本
                errorLog.BrowserVersion = ch.GetBrowserVersion();
                //客户端浏览器名称
                errorLog.BrowserType = ch.GetBrowserInfo();
                //获取用户IP
                errorLog.Ip = IpHelper.GetUserIp();
                // 异常页面
                errorLog.PageUrl = context.Request.Url.ToString();
                //异常消息
                errorLog.ErrMessage = ex.Message;
                //异常源
                errorLog.ErrSource = ex.Source;
                //堆栈轨迹
                errorLog.StackTrace = ex.StackTrace;
                //帮助连接
                errorLog.HelpLink = ex.HelpLink;

                //添加进数据库
                errorLog.Save();
            }
            catch (Exception) { }
        }
Exemplo n.º 2
0
 /// <summary>
 /// 更新IIS缓存中指定Id记录
 /// </summary>
 /// <param name="model">记录实体</param>
 public void SetModelForCache(ErrorLog model)
 {
     SetModelForCache(Transform(model));
 }
Exemplo n.º 3
0
        /// <summary>
        /// 添加与编辑ErrorLog记录
        /// </summary>
        /// <param name="page">当前页面指针</param>
        /// <param name="model">ErrorLog表实体</param>
        /// <param name="content">更新说明</param>
        /// <param name="isCache">是否更新缓存</param>
        /// <param name="isAddUseLog">是否添加用户操作日志</param>
        public void Save(Page page, ErrorLog model, string content = null, bool isCache = true, bool isAddUseLog = true)
        {
            try {
                //保存
                model.Save();

                //判断是否启用缓存
                if (CommonBll.IsUseCache() && isCache)
                {
                    SetModelForCache(model);
                }

                if (isAddUseLog)
                {
                    if (string.IsNullOrEmpty(content))
                    {
                        content = "{0}" + (model.Id == 0 ? "添加" : "编辑") + "ErrorLog记录成功,ID为【" + model.Id + "】";
                    }

                    //添加用户访问记录
                    UseLogBll.GetInstence().Save(page, content);
                }
            }
            catch (Exception e) {
                var result = "执行ErrorLogBll.Save()函数出错!";

                //出现异常,保存出错日志信息
                CommonBll.WriteLog(result, e);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// 将ErrorLog记录实体(SubSonic实体)转换为普通的实体(DataAccess.Model.ErrorLog)
        /// </summary>
        /// <param name="model">SubSonic插件生成的实体</param>
        /// <returns>DataAccess.Model.ErrorLog</returns>
        public DataAccess.Model.ErrorLog Transform(ErrorLog model)
        {
            if (model == null)
                return null;

            return new DataAccess.Model.ErrorLog
            {
                Id = model.Id,
                ErrTime = model.ErrTime,
                BrowserVersion = model.BrowserVersion,
                BrowserType = model.BrowserType,
                Ip = model.Ip,
                PageUrl = model.PageUrl,
                ErrMessage = model.ErrMessage,
                ErrSource = model.ErrSource,
                StackTrace = model.StackTrace,
                HelpLink = model.HelpLink,
                Type = model.Type,
            };
        }
Exemplo n.º 5
0
 public static void Setup(int testItems)
 {
     SetTestRepo();
     for(int i=0;i<testItems;i++){
         ErrorLog item=new ErrorLog();
         _testRepo._items.Add(item);
     }
 }
Exemplo n.º 6
0
 public static void Setup(ErrorLog item)
 {
     SetTestRepo();
     _testRepo._items.Add(item);
 }
Exemplo n.º 7
0
 public static void Setup(ErrorLog item)
 {
     SetTestRepo();
     _testRepo._items.Add(item);
 }