|
|
@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
using HybirdFrameworkCore.Entity;
|
|
|
|
|
|
|
|
using log4net;
|
|
|
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
|
|
using Microsoft.AspNetCore.Mvc.Filters;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace WebStarter.MyFilter;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class RequestFilter : Attribute, IActionFilter, IExceptionFilter, IResultFilter
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
private static readonly ILog Log = LogManager.GetLogger(typeof(RequestFilter));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void OnActionExecuting(ActionExecutingContext context)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Log.Info($"OnActionExecuting {context.HttpContext.Request.Path}");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void OnActionExecuted(ActionExecutedContext context)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Log.Info($"OnActionExecuted {context.HttpContext.Request.Path}, result = {context.Result}");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void OnException(ExceptionContext context)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Log.Error($"{context.Exception.StackTrace}");
|
|
|
|
|
|
|
|
if (!context.ExceptionHandled)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
context.ExceptionHandled = true;
|
|
|
|
|
|
|
|
Result<string> result = Result<string>.Fail("系统异常");
|
|
|
|
|
|
|
|
context.Result = new ObjectResult(result)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
StatusCode = StatusCodes.Status500InternalServerError
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void OnResultExecuting(ResultExecutingContext context)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void OnResultExecuted(ResultExecutedContext context)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|