解决日志写入异常

This commit is contained in:
token
2024-01-23 22:40:02 +08:00
parent e2bd7a4db3
commit ea83ef0a06
2 changed files with 11 additions and 4 deletions
+11 -3
View File
@@ -30,7 +30,15 @@ public class RequestLogService
{
while (_channel.Reader.TryRead(out var requestLog))
{
await _freeSql.Insert(requestLog).ExecuteAffrowsAsync();
try
{
requestLog.Id = Guid.NewGuid().ToString("N");
await _freeSql.Insert(requestLog).ExecuteAffrowsAsync();
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
}
}
@@ -39,10 +47,10 @@ public class RequestLogService
{
// 获取系统配置
var day = await _settingService.GetAsync<int>(Constant.Setting.LogRetentionTime);
// 计算时间差
var startTime = DateTime.Now.AddDays(-day);
// 删除数据
return await _freeSql.Delete<RequestLog>().Where(x => x.CreatedTime <= startTime).ExecuteAffrowsAsync();
}
-1
View File
@@ -6,7 +6,6 @@
"Microsoft.Hosting.Lifetime": "Information"
}
},
"Urls":"http://*:8080;https://*:8081",
"AllowedHosts": "*",
"ConnectionStrings": {
"DefaultConnection": "Data Source=/data/Gateway.db"