添加静态日志
This commit is contained in:
parent
980918efd3
commit
13a05a04c1
|
@ -0,0 +1,52 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
|
||||
namespace ShardingCore.Logger
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// Author: xjm
|
||||
/// Created: 2022/5/18 10:02:25
|
||||
/// Email: 326308290@qq.com
|
||||
public sealed class InternalLoggerFactory
|
||||
{
|
||||
static ILoggerFactory _defaultFactory;
|
||||
|
||||
|
||||
static ILoggerFactory NewDefaultFactory()
|
||||
{
|
||||
var f = new NullLoggerFactory();
|
||||
return f;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the default factory.
|
||||
/// </summary>
|
||||
public static ILoggerFactory DefaultFactory
|
||||
{
|
||||
get
|
||||
{
|
||||
ILoggerFactory factory = Volatile.Read(ref _defaultFactory);
|
||||
if (factory == null)
|
||||
{
|
||||
factory = NewDefaultFactory();
|
||||
ILoggerFactory current = Interlocked.CompareExchange(ref _defaultFactory, factory, null);
|
||||
if (current != null)
|
||||
{
|
||||
return current;
|
||||
}
|
||||
}
|
||||
return factory;
|
||||
}
|
||||
set => Volatile.Write(ref _defaultFactory, value);
|
||||
}
|
||||
public static ILogger<T> CreateLogger<T>() => DefaultFactory.CreateLogger<T>();
|
||||
public static ILogger CreateLogger(string categoryName) => DefaultFactory.CreateLogger(categoryName);
|
||||
}
|
||||
}
|
|
@ -10,13 +10,15 @@ using System;
|
|||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using ShardingCore.Extensions.InternalExtensions;
|
||||
using ShardingCore.Logger;
|
||||
using ShardingCore.Sharding.Parsers.Abstractions;
|
||||
|
||||
namespace ShardingCore.Sharding.ShardingExecutors
|
||||
{
|
||||
public class QueryCompilerContextFactory : IQueryCompilerContextFactory
|
||||
{
|
||||
private readonly ILogger<QueryCompilerContextFactory> _logger;
|
||||
private static readonly ILogger<QueryCompilerContextFactory> _logger =
|
||||
InternalLoggerFactory.CreateLogger<QueryCompilerContextFactory>();
|
||||
private static readonly IQueryableCombine _enumerableQueryableCombine;
|
||||
private static readonly IQueryableCombine _allQueryableCombine;
|
||||
private static readonly IQueryableCombine _constantQueryableCombine;
|
||||
|
@ -32,10 +34,6 @@ namespace ShardingCore.Sharding.ShardingExecutors
|
|||
_whereQueryableCombine = new WhereQueryableCombine();
|
||||
}
|
||||
|
||||
public QueryCompilerContextFactory(ILogger<QueryCompilerContextFactory> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public IQueryCompilerContext Create(IPrepareParseResult prepareParseResult)
|
||||
{
|
||||
|
|
|
@ -10,6 +10,7 @@ using ShardingCore.Extensions;
|
|||
using ShardingCore.Sharding.Abstractions;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using ShardingCore.Logger;
|
||||
|
||||
namespace ShardingCore.TableCreator
|
||||
{
|
||||
|
@ -21,14 +22,14 @@ namespace ShardingCore.TableCreator
|
|||
*/
|
||||
public class ShardingTableCreator<TShardingDbContext> : IShardingTableCreator<TShardingDbContext> where TShardingDbContext : DbContext, IShardingDbContext
|
||||
{
|
||||
private readonly ILogger<ShardingTableCreator<TShardingDbContext>> _logger;
|
||||
private static readonly ILogger<ShardingTableCreator<TShardingDbContext>> _logger =
|
||||
InternalLoggerFactory.CreateLogger<ShardingTableCreator<TShardingDbContext>>();
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
private readonly IShardingEntityConfigOptions<TShardingDbContext> _entityConfigOptions;
|
||||
private readonly IRouteTailFactory _routeTailFactory;
|
||||
|
||||
public ShardingTableCreator(ILogger<ShardingTableCreator<TShardingDbContext>> logger, IServiceProvider serviceProvider, IShardingEntityConfigOptions<TShardingDbContext> entityConfigOptions, IRouteTailFactory routeTailFactory)
|
||||
public ShardingTableCreator(IServiceProvider serviceProvider, IShardingEntityConfigOptions<TShardingDbContext> entityConfigOptions, IRouteTailFactory routeTailFactory)
|
||||
{
|
||||
_logger = logger;
|
||||
_serviceProvider = serviceProvider;
|
||||
_entityConfigOptions = entityConfigOptions;
|
||||
_routeTailFactory = routeTailFactory;
|
||||
|
|
|
@ -15,6 +15,7 @@ using ShardingCore.Core.VirtualRoutes;
|
|||
using ShardingCore.Core.VirtualRoutes.TableRoutes.Abstractions;
|
||||
using ShardingCore.Extensions;
|
||||
using ShardingCore.Jobs.Abstaractions;
|
||||
using ShardingCore.Logger;
|
||||
using ShardingCore.TableCreator;
|
||||
|
||||
namespace ShardingCore.VirtualRoutes.Abstractions
|
||||
|
@ -22,13 +23,9 @@ namespace ShardingCore.VirtualRoutes.Abstractions
|
|||
[ExcludeFromCodeCoverage]
|
||||
public abstract class AbstractShardingAutoCreateOperatorVirtualTableRoute<TEntity, TKey> : AbstractShardingOperatorVirtualTableRoute<TEntity, TKey>, IJob where TEntity : class
|
||||
{
|
||||
private readonly ILogger<AbstractShardingAutoCreateOperatorVirtualTableRoute<TEntity, TKey>> _logger;
|
||||
private static readonly ILogger<AbstractShardingAutoCreateOperatorVirtualTableRoute<TEntity, TKey>> _logger =
|
||||
InternalLoggerFactory.CreateLogger<AbstractShardingAutoCreateOperatorVirtualTableRoute<TEntity, TKey>>();
|
||||
|
||||
protected AbstractShardingAutoCreateOperatorVirtualTableRoute()
|
||||
{
|
||||
_logger = ShardingContainer
|
||||
.GetService<ILogger<AbstractShardingAutoCreateOperatorVirtualTableRoute<TEntity, TKey>>>();
|
||||
}
|
||||
/// <summary>
|
||||
/// 不可以设置一样
|
||||
/// </summary>
|
||||
|
|
Loading…
Reference in New Issue