Ejemplo n.º 1
0
        public async override void OnActionExecuting(HttpActionContext actionContext)
        {
            if (actionContext.ModelState.IsValid == false)
            {
                string __loggingResourceName = "Validation action filter";
                var service = new LoggingService();
        
                try
                {
                    //generate base log

                    var baseLog = service.GenerateBaseLog(ApiLogType.Warning, "ValidationFilter - Model not valid",
                        GetType(), service.GetCaller(),
                        ConfigurationManager.ConnectionStrings["AutoResolveContext"].ConnectionString);


                    var fullLog = await service.GenerateLog(actionContext.Request, actionContext.Response, baseLog);
                    service.WriteLog(baseLog.LoggingType, fullLog, baseLog.Exception);
                }
                catch (Exception ex)
                {
                    var errorLog =
                        await service.GenerateLog(actionContext.Request, actionContext.Response, new ApiBaseLog { LoggingType = ApiLogType.Fatal, Exception = ex, CurrentClass = this.GetType(), CurrentMethod = "", Message = "There has been a fatal error and logs cannot be generated" });
                    service.WriteLog(ApiLogType.Fatal, errorLog, ex);
                }

                actionContext.Response = actionContext.Request.CreateErrorResponse(
                            HttpStatusCode.BadRequest, actionContext.ModelState);
            }
        }