using System;
using System.Net;
using Library;
using Microsoft.AspNetCore.Mvc.Filters;

namespace MySystem
{
    public class GlobalExceptionsFilter : IExceptionFilter
    {
        public void OnException(ExceptionContext context)
        {
            string Message = context.Exception.Message;
            string StackTrace = context.Exception.StackTrace;
            function.WriteLog(DateTime.Now.ToString() + "\r\n" + Message + "\r\n" + StackTrace, "Global全局异常处理日志");
            context.HttpContext.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
            context.ExceptionHandled = true;
        }
    }
}
