コード例 #1
0
        public override async void OnException(HttpActionExecutedContext context)
        {
            var exception = context.Exception?.InnerException ?? context.Exception;

            var response = new ResponseModel <object>
            {
                Success = false,
                Message = "Internal server error",
                Data    = null
            };

            var json = JsonConvert.SerializeObject(response);

            context.Response = new HttpResponseMessage
            {
                Content = new StringContent(json, Encoding.UTF8, "application/json")
            };

            var input = string.Empty;

            if (context.Request.Content != null)
            {
                input = await context.Request.Content.ReadAsStringAsync();
            }

            _log.FatalFormat("Exception {0} - message: {1} - input: {2} - response: {3}", context.Request.RequestUri, exception.Dump(), input.Dump(), context.Dump());
        }