Esempio n. 1
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);
        }
Esempio n. 2
0
        /// <summary>
        /// 例外書込
        /// </summary>
        public void Fatal(Exception exception, ExceptionLogModel exceptionLogModel, int httpStatusCode)
        {
            var applicationErrorLogParameter = new List<object>();

            applicationErrorLogParameter.Add(exceptionLogModel.MemberId);

            applicationErrorLogParameter.Add(httpStatusCode);

            applicationErrorLogParameter.Add(exceptionLogModel.Url);

            applicationErrorLogParameter.Add(exceptionLogModel.UserAgent);

            applicationErrorLogParameter.Add(exceptionLogModel.UrlReferrer);

            applicationErrorLogParameter.Add(exceptionLogModel.SessionId);

            applicationErrorLogParameter.Add(exception);

            applicationErrorLogParameter.Add(exception.InnerException);

            Logger.Fatal(exception, LoggingResource.ApplicationErrorLogTemplete, applicationErrorLogParameter.ToArray());
        }
Esempio n. 3
0
        /// <summary>
        /// 例外書込
        /// </summary>
        public void Fatal(Exception exception, ExceptionLogModel exceptionLogModel)
        {
            var exeptionLogParameter = new List<object>();

            exeptionLogParameter.Add(exceptionLogModel.MemberId);

            exeptionLogParameter.Add(exceptionLogModel.ControllerName);

            exeptionLogParameter.Add(exceptionLogModel.ActionName);

            exeptionLogParameter.Add(exceptionLogModel.Url);

            exeptionLogParameter.Add(exceptionLogModel.UserAgent);

            exeptionLogParameter.Add(exceptionLogModel.UrlReferrer);

            exeptionLogParameter.Add(exceptionLogModel.SessionId);

            exeptionLogParameter.Add(exception);

            exeptionLogParameter.Add(exception.InnerException);

            Logger.Fatal(exception, LoggingResource.ExceptionLogTemplete, exeptionLogParameter.ToArray());
        }
Esempio n. 4
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));
        }