GlobalExceptionsFilter.cs 652 B

12345678910111213141516171819
  1. using System;
  2. using System.Net;
  3. using Library;
  4. using Microsoft.AspNetCore.Mvc.Filters;
  5. namespace MySystem
  6. {
  7. public class GlobalExceptionsFilter : IExceptionFilter
  8. {
  9. public void OnException(ExceptionContext context)
  10. {
  11. string Message = context.Exception.Message;
  12. string StackTrace = context.Exception.StackTrace;
  13. function.WriteLog(DateTime.Now.ToString() + "\r\n" + Message + "\r\n" + StackTrace, "Global全局异常处理日志");
  14. context.HttpContext.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
  15. context.ExceptionHandled = true;
  16. }
  17. }
  18. }