123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- using Microsoft.AspNetCore.Http;
- using Microsoft.AspNetCore.Mvc;using WMS.BZWeb;
- using Microsoft.AspNetCore.Mvc.Filters;
- using WMS.Info;
- using WMS.Util;
- using log4net;
- namespace WMS.BZWeb.Extensions
- {
- public class ExceptionFilter : IExceptionFilter
- {
-
- /// <summary>
- /// 发生异常时进入
- /// </summary>
- /// <param name="context"></param>
- public void OnException(ExceptionContext context)
- {
- if (context.ExceptionHandled == false)
- {
- context.Result = new ContentResult
- {
- Content = new ResInfo { code = EResponseCode.Fail, info = context.Exception.Message, data = "" }.ToJson(),//这里是把异常抛出。也可以不抛出。
- StatusCode = StatusCodes.Status200OK,
- ContentType = "text/html;charset=utf-8"
- };
- }
- context.ExceptionHandled = true;
-
- //LogFactory.GetLogger(typeof(ExceptionFilter)).Error(context.Exception );
- //var logIBLL = IocManager.Instance.GetService<LogIBLL>();
- //LogEntity logEntity = new LogEntity();
- //logEntity.F_CategoryId = 4;
- //logEntity.F_OperateTypeId = ((int)OperationType.Exception).ToString();
- //logEntity.F_OperateType = EnumAttribute.GetDescription(OperationType.Exception);
- //logEntity.F_OperateAccount = ContextHelper.GetItem("account") as string;
- //logEntity.F_OperateUserId = ContextHelper.GetItem("userId") as string;
- //logEntity.F_Module = context.HttpContext.Request.Path;
- //logEntity.F_IPAddress = context.HttpContext.Connection.RemoteIpAddress.ToString();
- //logEntity.F_ExecuteResult = -1;
- //logEntity.F_ExecuteResultJson = logIBLL.ExceptionFormat(context.Exception);
- //logIBLL.Write(logEntity).GetAwaiter().GetResult();
- }
- }
- }
|