Web api global Exception Handler
来源:互联网 发布:潇湘馆的竹叶 知乎 编辑:程序博客网 时间:2024/06/15 12:39
public class JgoExceptionFilterAttribute : ExceptionFilterAttribute
{
public override void OnException(HttpActionExecutedContext actionExecutedContext)
{
Utility.Logger.log.Error(
"Type:" + actionExecutedContext.Exception.GetType().ToString() +
":Url:" + actionExecutedContext.Request.RequestUri +
":Body:" + GetBodyFromRequest(actionExecutedContext) +
//":Message:" + actionExecutedContext.Exception.Message +
//":StackTrace:" + actionExecutedContext.Exception.StackTrace +
":BaseMessage:" + actionExecutedContext.Exception.GetBaseException().Message +
":BaseStackTrace:" + actionExecutedContext.Exception.GetBaseException().StackTrace
);
//Log Exception
//Utility.Logger.log.Error(actionExecutedContext.Exception.GetType().ToString() + ":" + actionExecutedContext.Exception.Message + ":" + actionExecutedContext.Exception.StackTrace + ":" + actionExecutedContext.Exception.StackTrace);
base.OnException(actionExecutedContext);
}
private string GetBodyFromRequest(HttpActionExecutedContext context)
{
string data;
using (var stream = context.Request.Content.ReadAsStreamAsync().Result)
{
if (stream.CanSeek)
{
stream.Position = 0;
}
data = context.Request.Content.ReadAsStringAsync().Result;
}
return data;
}
{
public override void OnException(HttpActionExecutedContext actionExecutedContext)
{
Utility.Logger.log.Error(
"Type:" + actionExecutedContext.Exception.GetType().ToString() +
":Url:" + actionExecutedContext.Request.RequestUri +
":Body:" + GetBodyFromRequest(actionExecutedContext) +
//":Message:" + actionExecutedContext.Exception.Message +
//":StackTrace:" + actionExecutedContext.Exception.StackTrace +
":BaseMessage:" + actionExecutedContext.Exception.GetBaseException().Message +
":BaseStackTrace:" + actionExecutedContext.Exception.GetBaseException().StackTrace
);
//Log Exception
//Utility.Logger.log.Error(actionExecutedContext.Exception.GetType().ToString() + ":" + actionExecutedContext.Exception.Message + ":" + actionExecutedContext.Exception.StackTrace + ":" + actionExecutedContext.Exception.StackTrace);
base.OnException(actionExecutedContext);
}
private string GetBodyFromRequest(HttpActionExecutedContext context)
{
string data;
using (var stream = context.Request.Content.ReadAsStreamAsync().Result)
{
if (stream.CanSeek)
{
stream.Position = 0;
}
data = context.Request.Content.ReadAsStringAsync().Result;
}
return data;
}
}
public class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
config.Filters.Add(new JgoExceptionFilterAttribute());
0 0
- Web api global Exception Handler
- Web API Global Error Handl
- struts global-exception-mappings
- struts global-exception-mappings解析
- 全局异常处理 global exception
- Contact Manager Web API 异常处理(Exception Handling)
- API References-global
- Exception handler interface
- Exception handler interface ' implementation
- JBPM知识点------exception-handler
- Handler替代Exception函数
- JBPM知识点------exception-handler
- spring-rest-exception-handler
- File Exception Handler
- SpringMVC Exception Handler
- Web.config & global.asax
- Dynamics CRM2016 通过web api来调用自定义action之global action
- org.springframework.web.util.NestedServletException: Handler processing failed; nested exception i
- webpack踩过的坑
- Android线程池使用心得
- Dockerfile创建自定义Docker镜像以及CMD与ENTRYPOINT指令的比较
- Ajax请求成功后,获取success中的返回的问题
- facebook zencart登录插件
- Web api global Exception Handler
- 用两个栈来实现一个队列,完成队列的Push和Pop操作。 队列中的元素为int类型。
- 《算法笔记-2》
- CenterOS7.2&Ubuntu14.04配置TURN服务器
- Android Studio提升项目的编译速度
- centos 重启 php-fpm
- 生产者/消费者问题的多种Java实现方式
- Codeforces Round #406 (Div. 2)
- 通过指针、数组,讲静态存储区、栈、堆的区别(转载)/C