فهرست منبع

😎修复日志写入独立数据库模式

zuohuaijun 2 سال پیش
والد
کامیت
49ce792071

+ 4 - 0
Admin.NET/Admin.NET.Core/Logging/DatabaseLoggingWriter.cs

@@ -22,6 +22,10 @@ public class DatabaseLoggingWriter : IDatabaseLoggingWriter, IDisposable
         _db = _serviceScope.ServiceProvider.GetRequiredService<ISqlSugarClient>();
         _sysConfigService = _serviceScope.ServiceProvider.GetRequiredService<SysConfigService>();
         _logger = _serviceScope.ServiceProvider.GetRequiredService<ILogger<DatabaseLoggingWriter>>();
+
+        // 切换日志独立数据库
+        if (SqlSugarSetup.ITenant.IsAnyConnection(SqlSugarConst.LogConfigId))
+            _db = SqlSugarSetup.ITenant.GetConnectionScope(SqlSugarConst.LogConfigId);
     }
 
     public async Task WriteAsync(LogMessage logMsg, bool flush)

+ 7 - 7
Admin.NET/Admin.NET.Core/SqlSugar/SqlSugarRepository.cs

@@ -22,13 +22,13 @@ public class SqlSugarRepository<T> : SimpleClient<T> where T : class, new()
             return;
         }
 
-        // 若实体贴有日志表特性,则返回日志库连接
-        if (typeof(T).IsDefined(typeof(LogTableAttribute), false))
-        {
-            if (iTenant.IsAnyConnection(SqlSugarConst.LogConfigId))
-                base.Context = iTenant.GetConnectionScope(SqlSugarConst.LogConfigId);
-            return;
-        }
+        //// 若实体贴有日志表特性,则返回日志库连接
+        //if (typeof(T).IsDefined(typeof(LogTableAttribute), false))
+        //{
+        //    if (iTenant.IsAnyConnection(SqlSugarConst.LogConfigId))
+        //        base.Context = iTenant.GetConnectionScope(SqlSugarConst.LogConfigId);
+        //    return;
+        //}
 
         // 若实体贴有系统表特性,则返回默认库连接
         if (typeof(T).IsDefined(typeof(SysTableAttribute), false))