添加Tnb.Vengine
This commit is contained in:
34
visualdev/Tnb.Vengine/DataAccess/SugarHelper.cs
Normal file
34
visualdev/Tnb.Vengine/DataAccess/SugarHelper.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using JNPF.Logging;
|
||||
using SqlSugar;
|
||||
|
||||
namespace Tnb.Vengine.DataAccess;
|
||||
|
||||
public class SugarHelper
|
||||
{
|
||||
public static void ConfigSugar(ISqlSugarClient db)
|
||||
{
|
||||
// 设置超时时间
|
||||
db.Ado.CommandTimeOut = 30;
|
||||
db.Aop.OnLogExecuted = (sql, pars) =>
|
||||
{
|
||||
var finalSql = UtilMethods.GetSqlString(db.CurrentConnectionConfig.DbType, sql, pars);
|
||||
if (db.Ado.SqlExecutionTime.TotalMilliseconds > 3000)
|
||||
{
|
||||
Log.Warning($"慢查询: {db.Ado.SqlExecutionTime.TotalMilliseconds}ms, SQL: " + finalSql);
|
||||
}
|
||||
else
|
||||
{
|
||||
var oldColor = Console.ForegroundColor;
|
||||
Console.ForegroundColor = ConsoleColor.Green;
|
||||
Console.WriteLine($"【{DateTime.Now.ToString("HH:mm:ss.fff")}——SQL执行完成】{db.Ado.SqlExecutionTime.TotalMilliseconds} ms");
|
||||
Console.WriteLine(finalSql);
|
||||
Console.ForegroundColor = oldColor;
|
||||
Console.WriteLine();
|
||||
}
|
||||
};
|
||||
db.Aop.OnError = (ex) =>
|
||||
{
|
||||
Log.Error(UtilMethods.GetSqlString(db.CurrentConnectionConfig.DbType, ex.Sql, (SugarParameter[])ex.Parametres));
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user