Пример #1
0
        public void OnException(ExceptionContext filterContext)
        {
            string name = "Guest";

            if (filterContext.HttpContext.User.Identity.IsAuthenticated)
            {
                name = filterContext.HttpContext.User.Identity.Name;
            }
            if (!filterContext.ExceptionHandled)
            {
                ExceptionLogModel logger = new ExceptionLogModel()
                {
                    UserName            = name,
                    ExceptionMessage    = filterContext.Exception.Message,
                    ControllerName      = filterContext.RouteData.Values["controller"].ToString(),
                    ExceptionStackTrace = filterContext.Exception.StackTrace,
                    LogTime             = DateTime.Now
                };
                XmlFileManager manager = new XmlFileManager();
                manager.XmlSave(logger);
            }
        }
Пример #2
0
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            var    request = filterContext.HttpContext.Request;
            string name    = "Guest";

            if (filterContext.HttpContext.User.Identity.IsAuthenticated)
            {
                name = filterContext.HttpContext.User.Identity.Name;
            }

            LogData data = new LogData
            {
                UserName   = name,
                UserAction = request.RawUrl,
                Date       = DateTime.Now
            };

            XmlFileManager xmlFileManager = new XmlFileManager();

            xmlFileManager.XmlSave(data);

            base.OnActionExecuting(filterContext);
        }