移除一个地方的console.log,使用静态日志,无需依赖logging

This commit is contained in:
xuejiaming 2022-06-15 17:53:43 +08:00
parent 4dc6d9d69c
commit 3527e00ec0
4 changed files with 17 additions and 10 deletions

View File

@ -51,12 +51,18 @@ namespace Sample.MySql
o.AddShardingTableRoute<SysUserModVirtualTableRoute>();
o.UseShardingQuery((conStr, builder) =>
{
builder.UseMySql(conStr, new MySqlServerVersion(new Version())).UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking).UseLoggerFactory(efLogger);
builder.UseMySql(conStr, new MySqlServerVersion(new Version())
,b=>b.EnableRetryOnFailure()
)
.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking).UseLoggerFactory(efLogger);
//builder.UseMySql(conStr, new MySqlServerVersion(new Version()));
});
o.UseShardingTransaction((connection, builder) =>
{
builder.UseMySql(connection, new MySqlServerVersion(new Version())).UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking).UseLoggerFactory(efLogger);
builder.UseMySql(connection, new MySqlServerVersion(new Version())
,b=>b.EnableRetryOnFailure()
)
.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking).UseLoggerFactory(efLogger);
});
})
.AddConfig(op =>

View File

@ -6,6 +6,7 @@ using Microsoft.Extensions.Logging;
using ShardingCore.Extensions;
using ShardingCore.Jobs;
using ShardingCore.Jobs.Abstaractions;
using ShardingCore.Logger;
using ShardingCore.Sharding.MergeEngines.ParallelControl;
namespace ShardingCore.Bootstrapers
@ -22,14 +23,15 @@ namespace ShardingCore.Bootstrapers
private readonly IEnumerable<IDbContextTypeCollector> _dbContextTypeCollectors;
private readonly DoOnlyOnce _doOnlyOnce = new DoOnlyOnce();
public ShardingBootstrapper(IServiceProvider serviceProvider,ILogger<ShardingBootstrapper> logger,IEnumerable<IDbContextTypeCollector> dbContextTypeCollectors)
public ShardingBootstrapper(IServiceProvider serviceProvider,ILoggerFactory loggerFactory,IEnumerable<IDbContextTypeCollector> dbContextTypeCollectors)
{
_logger = logger;
_dbContextTypeCollectors = dbContextTypeCollectors;
ShardingContainer.SetServices(serviceProvider);
InternalLoggerFactory.DefaultFactory = loggerFactory;
_logger = InternalLoggerFactory.DefaultFactory .CreateLogger<ShardingBootstrapper>();
_dbContextTypeCollectors = dbContextTypeCollectors;
}
/// <summary>
/// Æô¶¯
/// 启动
/// </summary>
public void Start()
{

View File

@ -27,7 +27,6 @@ namespace ShardingCore.EFCores
public ShardingModelSource(ModelSourceDependencies dependencies) : base(dependencies)
{
Check.NotNull(dependencies, nameof(dependencies));
Console.WriteLine($"ShardingModelSource:{Guid.NewGuid()}");
Dependencies = dependencies;
}

View File

@ -87,17 +87,17 @@ namespace ShardingCore.Helpers
var declaredConstructors = contextType.GetTypeInfo().DeclaredConstructors.ToList();
if (declaredConstructors.Count != 1)
{
throw new ArgumentException($"dbcontext : {contextType} declared constructor count more {contextType}");
throw new ArgumentException($"dbcontext : {contextType} declared constructor count more {contextType},if u want support multi constructor params plz replace ${nameof(IDbContextCreator)} interface");
}
if (declaredConstructors[0].GetParameters().Length != 1)
{
throw new ArgumentException($"dbcontext : {contextType} declared constructor parameters more ");
throw new ArgumentException($"dbcontext : {contextType} declared constructor parameters more ,if u want support multi constructor params plz replace ${nameof(IDbContextCreator)} interface");
}
var paramType = declaredConstructors[0].GetParameters()[0].ParameterType;
if (paramType != typeof(ShardingDbContextOptions) && paramType != typeof(DbContextOptions) && paramType != typeof(DbContextOptions<TContext>))
{
throw new ArgumentException($"dbcontext : {contextType} declared constructor parameters should use {typeof(ShardingDbContextOptions)} or {typeof(DbContextOptions)} or {typeof(DbContextOptions<TContext>)} ");
throw new ArgumentException($"dbcontext : {contextType} declared constructor parameters should use {typeof(ShardingDbContextOptions)} or {typeof(DbContextOptions)} or {typeof(DbContextOptions<TContext>)},if u want support multi constructor params plz replace ${nameof(IDbContextCreator)} interface ");
}
//if (!contextType.IsShardingDbContext())