Exemple #1
0
        public void OnActionExecuted(ActionExecutedContext filterContext)
        {
            try
            {
                if (ParameterValue.SYS01001)
                {
                    Guid id = new Guid(filterContext.HttpContext.Response.Headers["RequestID"].FirstOrDefault());

                    if (id != null && id != Guid.Empty)
                    {
                        LogContext.UpdateRequest(id);

                        var result = filterContext.Result;
                        if (result is JsonResult json)
                        {
                            var data = json.Value;
                            if (data != null && data is APIResultVM)
                            {
                                if ((data as APIResultVM).Errors != null && (data as APIResultVM).Errors.Count > 0)
                                {
                                    LogContext.AddErrorRange(id.ToString(), (data as APIResultVM).Errors);
                                    filterContext.HttpContext.Response.StatusCode = 500;
                                }
                            }
                        }

                        LogContext.Save();
                    }
                }
            }
            catch (Exception Ex)
            {
                Console.WriteLine("Error Message:" + Ex.Message + "/n Source: " + Ex.Source + "/n StackTrace: " + Ex.StackTrace);
            }
        }