我有一个网络API我沟通。从Web API错误中筛选异常堆栈跟踪?
当异常发生时,我得到以下JSON模板:
{
"Message": "An error has occurred.",
"ExceptionMessage": "Index was outside the bounds of the array.",
"ExceptionType": "System.IndexOutOfRangeException",
"StackTrace": " at WebApiTest.TestController.Post(Uri uri) in c:\\Temp\\WebApiTest\\WebApiTest\\TestController.cs:line 18\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClassf.<GetExecutor>b__9(Object instance, Object[] methodParameters)\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments)\r\n at System.Threading.Tasks.TaskHelpers.RunSynchronously[TResult](Func`1 func, CancellationToken cancellationToken)"
}
我想要什么的JSON,包括只是“消息”和“ExceptionMessage”性质,但仍对返回整个堆栈控制追踪追踪。
我使用
GlobalConfiguration.Configuration.IncludeErrorDetailPolicy
尝试,但似乎这是全有或全无,要么只是单一的“消息”属性或设置它时,“总是”获得完整的对象。
任何简单的方法来实现这一目标?
援助将不胜感激。
谢谢,我会研究它。 –
对我来说它完美无瑕。您可以使用自定义例外 –