Exemple #1
0
        protected void Application_Error(object sender, EventArgs e)
        {
            var exception = Server.GetLastError();

            Response.Clear();

            var writeLogFileService = new WriteLogFileService(WriteLogFileConst.ExceptionLoggerName);

            int httpStatusCode = 0;

            if (HttpContext.Current.Session == null)
            {
                httpStatusCode = 500;

                writeLogFileService.Fatal("HttpContext.Current.Session is Null.");
            }
            else if (exception == null)
            {
                httpStatusCode = 500;

                writeLogFileService.Fatal("ExceptionObject is Null.");
            }
            else
            {
                //例外書き込み用
                var exceptionLogModel = new ExceptionLogModel()
                {
                    MemberId = HttpContext.Current.Session["CurrentUser"].GetNullableLong(),
                    Url = HttpContext.Current.Request.Url.UriString(),
                    UserAgent = HttpContext.Current.Request.UserAgent,
                    UrlReferrer = HttpContext.Current.Request.UrlReferrer.UriString(),
                    SessionId = HttpContext.Current.Session.SessionID,
                };

                httpStatusCode = exception.GetHttpCode();

                writeLogFileService.Fatal(exception, exceptionLogModel, httpStatusCode);
            }

            var action = string.Empty;

            switch (httpStatusCode)
            {
                case 404:
                    action = "Error404";
                    break;
                default:
                    action = "Error500";
                    break;
            }

            Server.ClearError();

            //Todo:エラー用の設定をWeb.configでやるべき
            Response.Redirect(String.Format("~/errorpage/{0}/", action));
        }
Exemple #2
0
        /// <summary>
        /// ログ書き込み
        /// </summary>
        public void WriteLog(ControllerContext filterContext)
        {
            var writeLogFileService = new WriteLogFileService(filterContext, WriteLogFileConst.ExceptionLoggerName);

            var exceptionContext = (ExceptionContext)filterContext;

            //例外書き込み用
            var exceptionLogModel = new ExceptionLogModel()
            {
                MemberId = filterContext.HttpContext.Session["CurrentUser"].GetNullableLong(),
                ControllerName = filterContext.RouteData.Values["controller"].GetString(),
                ActionName = filterContext.RouteData.Values["action"].GetString(),
                Url = filterContext.HttpContext.Request.Url.UriString(),
                UserAgent = filterContext.HttpContext.Request.UserAgent,
                UrlReferrer = filterContext.HttpContext.Request.UrlReferrer.UriString(),
                SessionId = filterContext.HttpContext.Session.SessionID,
            };

            writeLogFileService.Fatal(exceptionContext.Exception, exceptionLogModel);
        }