新增执行sql超时记录日志

This commit is contained in:
不做码农 2023-12-07 11:33:19 +08:00
parent 0bcdb1cdfc
commit c7e6e322bc
2 changed files with 18 additions and 0 deletions

View File

@ -39,6 +39,7 @@
"DemoMode": false, // "DemoMode": false, //
"SingleLogin": false, /// "SingleLogin": false, ///
"workId": 1, //id "workId": 1, //id
"sqlExecutionTime": 5,//Sql
"Upload": { "Upload": {
"uploadUrl": "http://localhost:8888", //访 "uploadUrl": "http://localhost:8888", //访
"localSavePath": "", // wwwroot "localSavePath": "", // wwwroot

View File

@ -4,6 +4,7 @@ using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
using SqlSugar.IOC; using SqlSugar.IOC;
using ZR.Common;
using ZR.Model.System; using ZR.Model.System;
namespace ZR.ServiceCore.SqlSugar namespace ZR.ServiceCore.SqlSugar
@ -202,6 +203,22 @@ namespace ZR.ServiceCore.SqlSugar
#endregion #endregion
} }
}; };
db.GetConnectionScope(configId).Aop.OnLogExecuted = (sql, pars) =>
{
var sqlExecutionTime = AppSettings.Get<int>("sqlExecutionTime");
if (db.Ado.SqlExecutionTime.TotalSeconds > sqlExecutionTime)
{
//代码CS文件名
var fileName = db.Ado.SqlStackTrace.FirstFileName;
//代码行数
var fileLine = db.Ado.SqlStackTrace.FirstLine;
//方法名
var FirstMethodName = db.Ado.SqlStackTrace.FirstMethodName;
var logInfo = $"Sql执行超时用时{db.Ado.SqlExecutionTime.TotalSeconds}秒【{sql}】,fileName={fileName},line={fileLine},methodName={FirstMethodName}";
WxNoticeHelper.SendMsg("Sql请求时间过长",logInfo);
logger.Warn(logInfo);
}
};
} }
private static object GetParsValue(SugarParameter x) private static object GetParsValue(SugarParameter x)