/// <summary> /// every exception will entry this method /// and will output log file at App_Data\logs /// </summary> /// <param name="actionExecutedContext"></param> public override void OnException(System.Web.Http.Filters.HttpActionExecutedContext actionExecutedContext) { base.OnException(actionExecutedContext); logger.Log(LogLevel.Error, actionExecutedContext.Exception); var errorMessage = actionExecutedContext.Exception.Message; var result = new ApiResultEntity() { StatusCode = HttpStatusCode.OK, Status = "ERROR", ErrorMessage = errorMessage }; actionExecutedContext.Response = actionExecutedContext.Request.CreateResponse(result.StatusCode, result); }
/// <summary> /// Action Executed package output format /// </summary> /// <param name="actionExecutedContext"></param> public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext) { { // exclude exception action if (actionExecutedContext.Exception != null) { return; } // exclude download controller if (actionExecutedContext.Request.RequestUri.ToString().IndexOf("download") > 0 || actionExecutedContext.Request.RequestUri.ToString().IndexOf("DownloadPos") > 0) { return; } base.OnActionExecuted(actionExecutedContext); ApiResultEntity result = new ApiResultEntity(); result.Status = "OK"; result.StatusCode = actionExecutedContext.ActionContext.Response.StatusCode; if (actionExecutedContext.ActionContext.Response.Content != null) { result.Data = actionExecutedContext.ActionContext.Response.Content.ReadAsAsync <object>().Result; } actionExecutedContext.Response = actionExecutedContext.Request.CreateResponse(result.StatusCode, result); } }