コード例 #1
0
        /// <summary>
        /// Logs actions using EFLoggingLayer
        /// </summary>
        /// <param name="filterContext">Context of filter</param>
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            EFLoggingLayer layer        = new EFLoggingLayer();
            var            request      = filterContext.HttpContext.Request;
            ActionDetail   actionDetail = new ActionDetail()
            {
                UserName = request.IsAuthenticated ? filterContext.HttpContext.User.Identity.Name : Anonymous,
                //HTTP_X_FORWARDED_FOR stands for HTTP header used by proxy servers
                IPAddress  = request.IsLocal ? Local : request.ServerVariables["HTTP_X_FORWARDED_FOR"] ?? request.UserHostAddress,
                Controller = request.RequestContext.RouteData.Values["action"].ToString(),
                Action     = request.RequestContext.RouteData.Values["controller"].ToString(),
                RawURL     = request.RawUrl,
                Date       = DateTime.UtcNow
            };

            layer.LogAction(actionDetail);
            base.OnActionExecuting(filterContext);
        }
コード例 #2
0
        /// <summary>
        /// Logs exceptions using EFLoggingLayer
        /// </summary>
        /// <param name="filterContext">Context of filter</param>
        public override void OnException(ExceptionContext filterContext)
        {
            EFLoggingLayer  layer           = new EFLoggingLayer();
            ExceptionDetail exceptionDetail = new ExceptionDetail()
            {
                Message    = filterContext.Exception.Message,
                StackTrace = filterContext.Exception.StackTrace,
                Controller = filterContext.RouteData.Values["controller"].ToString(),
                Action     = filterContext.RouteData.Values["action"].ToString(),
                Date       = DateTime.UtcNow
            };

            filterContext.ExceptionHandled = true;
            layer.LogException(exceptionDetail);
            filterContext.Result = new RedirectToRouteResult(new System.Web.Routing.RouteValueDictionary {
                { "controller", "Exception" },
                { "action", "DisplayExceptionPage" }
            });
        }