Example #1
0
        protected void Application_Error()
        {
            var exception = this.Server.GetLastError();

            if (EFMigrationsManagerConfig.HandleEFMigrationException(exception, this.Server, this.Response, this.Context))
            {
                return;
            }
            this.logger.Fatal(exception, exception.GetBaseException().Message);
        }
Example #2
0
        protected void Application_Error()
        {
            var exception = Server.GetLastError();

            if (EFMigrationsManagerConfig.HandleEFMigrationException(exception, Server, Response, Context))
                return;
            var message = exception.Message;
            var stackTrace = exception.StackTrace;
            var Source = exception.Source;

            HttpContext httpContext = HttpContext.Current;
            var controllerName = string.Empty;
            var actionName = string.Empty;
            var messageTag = string.Empty;
            var code = string.Empty;
            HttpException httpException = exception as HttpException;
            if (httpException != null)
            {
                code = $"{httpException.ErrorCode}:{httpException.WebEventCode}";
            }
            if (httpContext != null)
            {
                var requestContext = ((MvcHandler)httpContext.CurrentHandler).RequestContext;
                controllerName = requestContext.RouteData.GetRequiredString("controller");
                actionName = requestContext.RouteData.GetRequiredString("action");



                /* when the request is ajax the system can automatically handle a mistake with a JSON response. then overwrites the default response */
                if (requestContext.HttpContext.Request.IsAjaxRequest())
                {
                    messageTag = "Ajax";
                }
                else
                {
                    messageTag = "Mvc";
                }

            }

            DatabaseFactory.CreateDatabase().ExecuteSPNonQuery("[dbo].[SP_InsertMessages]",
                new
                {
                    Group = MessageGroup.System,
                    ExtensionKey1 = Source,
                    Type = MessageType.Error,
                    Content = message,
                    Tags = messageTag,
                    Code = code,
                    Method = $"{controllerName}/{actionName}",
                    StackTrace = stackTrace,
                    User = Auth.CurrentUserName
                }
                );
        }