Compare commits
No commits in common. "6f746d94688c51bdb5a8a4c692d59c0ad0512ccc" and "076074644869ac5115112ce8d46779075e80d864" have entirely different histories.
6f746d9468
...
0760746448
|
|
@ -583,11 +583,11 @@
|
||||||
日志
|
日志
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
<member name="M:langguanApi.Middleware.CustomerExceptionFilter.#ctor(langguanApi.Service.LogService)">
|
<member name="M:langguanApi.Middleware.CustomerExceptionFilter.#ctor(Microsoft.Extensions.Logging.ILoggerFactory)">
|
||||||
<summary>
|
<summary>
|
||||||
构参
|
构参
|
||||||
</summary>
|
</summary>
|
||||||
<param name="logService"></param>
|
<param name="loggerFactory"></param>
|
||||||
</member>
|
</member>
|
||||||
<member name="M:langguanApi.Middleware.CustomerExceptionFilter.OnExceptionAsync(Microsoft.AspNetCore.Mvc.Filters.ExceptionContext)">
|
<member name="M:langguanApi.Middleware.CustomerExceptionFilter.OnExceptionAsync(Microsoft.AspNetCore.Mvc.Filters.ExceptionContext)">
|
||||||
<summary>
|
<summary>
|
||||||
|
|
@ -1231,21 +1231,6 @@
|
||||||
国几排放量
|
国几排放量
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
<member name="T:langguanApi.Model.Entity.LogEntity">
|
|
||||||
<summary>
|
|
||||||
日志实体类
|
|
||||||
</summary>
|
|
||||||
</member>
|
|
||||||
<member name="P:langguanApi.Model.Entity.LogEntity.Level">
|
|
||||||
<summary>
|
|
||||||
日志等级
|
|
||||||
</summary>
|
|
||||||
</member>
|
|
||||||
<member name="P:langguanApi.Model.Entity.LogEntity.msg">
|
|
||||||
<summary>
|
|
||||||
日志内容
|
|
||||||
</summary>
|
|
||||||
</member>
|
|
||||||
<member name="T:langguanApi.Model.Entity.Menu">
|
<member name="T:langguanApi.Model.Entity.Menu">
|
||||||
<summary>
|
<summary>
|
||||||
菜单实体类
|
菜单实体类
|
||||||
|
|
@ -2438,24 +2423,6 @@
|
||||||
<param name="input"></param>
|
<param name="input"></param>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
</member>
|
</member>
|
||||||
<member name="T:langguanApi.Service.LogService">
|
|
||||||
<summary>
|
|
||||||
日志服务
|
|
||||||
</summary>
|
|
||||||
</member>
|
|
||||||
<member name="M:langguanApi.Service.LogService.#ctor(Microsoft.Extensions.Configuration.IConfiguration)">
|
|
||||||
<summary>
|
|
||||||
日志服务
|
|
||||||
</summary>
|
|
||||||
<param name="config"></param>
|
|
||||||
</member>
|
|
||||||
<member name="M:langguanApi.Service.LogService.addLog(langguanApi.Model.Entity.LogEntity)">
|
|
||||||
<summary>
|
|
||||||
添加日志
|
|
||||||
</summary>
|
|
||||||
<param name="log"></param>
|
|
||||||
<returns></returns>
|
|
||||||
</member>
|
|
||||||
<member name="M:langguanApi.Service.MenuService.AddMenu(langguanApi.Model.Entity.AddMenuDto)">
|
<member name="M:langguanApi.Service.MenuService.AddMenu(langguanApi.Model.Entity.AddMenuDto)">
|
||||||
<summary>
|
<summary>
|
||||||
新增菜单
|
新增菜单
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
using langguanApi.Service;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using Microsoft.AspNetCore.Mvc.Filters;
|
using Microsoft.AspNetCore.Mvc.Filters;
|
||||||
|
|
||||||
namespace langguanApi.Middleware
|
namespace langguanApi.Middleware
|
||||||
|
|
@ -9,21 +8,21 @@ namespace langguanApi.Middleware
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 日志
|
/// 日志
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public LogService _logger;
|
public ILogger _logger;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 构参
|
/// 构参
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="logService"></param>
|
/// <param name="loggerFactory"></param>
|
||||||
public CustomerExceptionFilter(LogService logService)
|
public CustomerExceptionFilter(ILoggerFactory loggerFactory)
|
||||||
{
|
{
|
||||||
_logger = logService;
|
_logger = loggerFactory.CreateLogger<CustomerExceptionFilter>();
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 重写
|
/// 重写
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="context"></param>
|
/// <param name="context"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task OnExceptionAsync(ExceptionContext context)
|
public Task OnExceptionAsync(ExceptionContext context)
|
||||||
{
|
{
|
||||||
if (context.ExceptionHandled == false)
|
if (context.ExceptionHandled == false)
|
||||||
{
|
{
|
||||||
|
|
@ -31,18 +30,11 @@ namespace langguanApi.Middleware
|
||||||
context.HttpContext.Response.StatusCode = 400;
|
context.HttpContext.Response.StatusCode = 400;
|
||||||
context.Result = new JsonResult(json);
|
context.Result = new JsonResult(json);
|
||||||
}
|
}
|
||||||
await _logger.addLog(new Model.Entity.LogEntity()
|
_logger.LogError($"请求出现异常,地址:{context.HttpContext?.Request?.Path}," +
|
||||||
{
|
|
||||||
Path = context.HttpContext.Request.Path,
|
|
||||||
msg = context.Exception.Message,
|
|
||||||
Level = "Error"
|
|
||||||
});
|
|
||||||
Console.WriteLine($"请求出现异常,地址:{context.HttpContext?.Request?.Path}," +
|
|
||||||
$"请求方式:{context.HttpContext.Request.Method},异常信息:{context.Exception.Message}");
|
$"请求方式:{context.HttpContext.Request.Method},异常信息:{context.Exception.Message}");
|
||||||
|
|
||||||
//记录异常已经处理
|
//记录异常已经处理
|
||||||
context.ExceptionHandled = true;
|
context.ExceptionHandled = true;
|
||||||
// return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,19 +0,0 @@
|
||||||
namespace langguanApi.Model.Entity
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// 日志实体类
|
|
||||||
/// </summary>
|
|
||||||
public class LogEntity : BaseModel
|
|
||||||
{
|
|
||||||
public string Path { get; set; }
|
|
||||||
/// <summary>
|
|
||||||
/// 日志等级
|
|
||||||
/// </summary>
|
|
||||||
public string Level { get; set; }
|
|
||||||
/// <summary>
|
|
||||||
/// 日志内容
|
|
||||||
/// </summary>
|
|
||||||
public string msg { get; set; }
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,33 +0,0 @@
|
||||||
using langguanApi.Common.Proxy;
|
|
||||||
using langguanApi.Extensions.AutoDI;
|
|
||||||
using langguanApi.Model;
|
|
||||||
using langguanApi.Model.Entity;
|
|
||||||
|
|
||||||
namespace langguanApi.Service
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// 日志服务
|
|
||||||
/// </summary>
|
|
||||||
[ServiceInjection(InjectionType.Transient)]
|
|
||||||
public class LogService : BaseService<LogEntity>
|
|
||||||
{
|
|
||||||
private readonly IConfiguration _configuration;
|
|
||||||
/// <summary>
|
|
||||||
/// 日志服务
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="config"></param>
|
|
||||||
public LogService(IConfiguration config) : base(config, nameof(LogEntity))
|
|
||||||
{
|
|
||||||
_configuration = config;
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// 添加日志
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="log"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public async Task addLog(LogEntity log)
|
|
||||||
{
|
|
||||||
await base.CreateAsync(log);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue