Compare commits

..

No commits in common. "6f746d94688c51bdb5a8a4c692d59c0ad0512ccc" and "076074644869ac5115112ce8d46779075e80d864" have entirely different histories.

4 changed files with 10 additions and 103 deletions

View File

@ -583,11 +583,11 @@
日志
</summary>
</member>
<member name="M:langguanApi.Middleware.CustomerExceptionFilter.#ctor(langguanApi.Service.LogService)">
<member name="M:langguanApi.Middleware.CustomerExceptionFilter.#ctor(Microsoft.Extensions.Logging.ILoggerFactory)">
<summary>
构参
</summary>
<param name="logService"></param>
<param name="loggerFactory"></param>
</member>
<member name="M:langguanApi.Middleware.CustomerExceptionFilter.OnExceptionAsync(Microsoft.AspNetCore.Mvc.Filters.ExceptionContext)">
<summary>
@ -1231,21 +1231,6 @@
国几排放量
</summary>
</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">
<summary>
菜单实体类
@ -2438,24 +2423,6 @@
<param name="input"></param>
<returns></returns>
</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)">
<summary>
新增菜单

View File

@ -1,5 +1,4 @@
using langguanApi.Service;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
namespace langguanApi.Middleware
@ -9,21 +8,21 @@ namespace langguanApi.Middleware
/// <summary>
/// 日志
/// </summary>
public LogService _logger;
public ILogger _logger;
/// <summary>
/// 构参
/// </summary>
/// <param name="logService"></param>
public CustomerExceptionFilter(LogService logService)
/// <param name="loggerFactory"></param>
public CustomerExceptionFilter(ILoggerFactory loggerFactory)
{
_logger = logService;
_logger = loggerFactory.CreateLogger<CustomerExceptionFilter>();
}
/// <summary>
/// 重写
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
public async Task OnExceptionAsync(ExceptionContext context)
public Task OnExceptionAsync(ExceptionContext context)
{
if (context.ExceptionHandled == false)
{
@ -31,18 +30,11 @@ namespace langguanApi.Middleware
context.HttpContext.Response.StatusCode = 400;
context.Result = new JsonResult(json);
}
await _logger.addLog(new Model.Entity.LogEntity()
{
Path = context.HttpContext.Request.Path,
msg = context.Exception.Message,
Level = "Error"
});
Console.WriteLine($"请求出现异常,地址:{context.HttpContext?.Request?.Path}" +
_logger.LogError($"请求出现异常,地址:{context.HttpContext?.Request?.Path}" +
$"请求方式:{context.HttpContext.Request.Method},异常信息:{context.Exception.Message}");
//记录异常已经处理
context.ExceptionHandled = true;
// return Task.CompletedTask;
return Task.CompletedTask;
}
}
}

View File

@ -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; }
}
}

View File

@ -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);
}
}
}