mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-03-22 10:34:30 +08:00
feat(architecture): 为架构上下文添加日志工厂支持
- 在ArchitectureContext构造函数中添加ILoggerFactory参数 - 为IArchitectureContext接口添加LoggerFactory属性 - 在Architecture的Initialize和InitializeAsync方法中传递loggerFactory - 修改AbstractContextUtility初始化逻辑,使用NoopLoggerFactory创建默认logger - 新增ILogAware接口用于支持日志记录功能 - [no tag]
This commit is contained in:
parent
8913f2fb2c
commit
543e32eb6a
@ -232,7 +232,7 @@ public abstract class Architecture(
|
||||
public void Initialize()
|
||||
{
|
||||
_logger = Configuration.LoggerFactory.GetLogger(GetType().Name);
|
||||
_context ??= new ArchitectureContext(Container, TypeEventSystem, _logger);
|
||||
_context ??= new ArchitectureContext(Container, TypeEventSystem, _logger, Configuration.LoggerFactory);
|
||||
|
||||
// 创建架构运行时实例
|
||||
Runtime = new ArchitectureRuntime(_context);
|
||||
@ -283,7 +283,7 @@ public abstract class Architecture(
|
||||
public async Task InitializeAsync()
|
||||
{
|
||||
_logger = Configuration.LoggerFactory.GetLogger(GetType().Name);
|
||||
_context ??= new ArchitectureContext(Container, TypeEventSystem, _logger);
|
||||
_context ??= new ArchitectureContext(Container, TypeEventSystem, _logger, Configuration.LoggerFactory);
|
||||
|
||||
// 创建架构运行时实例
|
||||
Runtime = new ArchitectureRuntime(_context);
|
||||
|
||||
@ -13,16 +13,21 @@ namespace GFramework.Core.architecture;
|
||||
/// 架构上下文类,提供对系统、模型、工具等组件的访问以及命令、查询、事件的执行管理
|
||||
/// </summary>
|
||||
public class ArchitectureContext(
|
||||
IIocContainer container,
|
||||
ITypeEventSystem typeEventSystem,
|
||||
ILogger logger)
|
||||
IIocContainer container,
|
||||
ITypeEventSystem typeEventSystem,
|
||||
ILogger logger,
|
||||
ILoggerFactory? loggerFactory)
|
||||
: IArchitectureContext
|
||||
{
|
||||
private readonly IIocContainer _container = container ?? throw new ArgumentNullException(nameof(container));
|
||||
private readonly ITypeEventSystem _typeEventSystem = typeEventSystem ?? throw new ArgumentNullException(nameof(typeEventSystem));
|
||||
|
||||
private readonly ITypeEventSystem _typeEventSystem =
|
||||
typeEventSystem ?? throw new ArgumentNullException(nameof(typeEventSystem));
|
||||
|
||||
public ILogger Logger { get; } = logger ?? throw new ArgumentNullException(nameof(logger));
|
||||
public ILoggerFactory LoggerFactory { get; } = loggerFactory ?? new NoopLoggerFactory();
|
||||
internal IArchitectureRuntime Runtime { get; set; } = null!;
|
||||
|
||||
|
||||
#region Component Retrieval
|
||||
|
||||
/// <summary>
|
||||
@ -143,4 +148,4 @@ public class ArchitectureContext(
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@ -81,7 +81,10 @@ public interface IArchitectureContext
|
||||
/// 获取日志记录器
|
||||
/// </summary>
|
||||
ILogger Logger { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取日志工厂
|
||||
/// </summary>
|
||||
ILoggerFactory LoggerFactory { get; }
|
||||
/// <summary>
|
||||
/// 取消注册事件监听器
|
||||
/// </summary>
|
||||
|
||||
15
GFramework.Core/rule/ILogAware.cs
Normal file
15
GFramework.Core/rule/ILogAware.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using GFramework.Core.logging;
|
||||
|
||||
namespace GFramework.Core.rule;
|
||||
|
||||
/// <summary>
|
||||
/// 定义一个支持日志记录的接口,允许实现类设置和使用日志记录器
|
||||
/// </summary>
|
||||
public interface ILogAware
|
||||
{
|
||||
/// <summary>
|
||||
/// 设置日志记录器
|
||||
/// </summary>
|
||||
/// <param name="logger">要设置的ILogger实例</param>
|
||||
void SetLogger(ILogger logger);
|
||||
}
|
||||
@ -9,7 +9,7 @@ namespace GFramework.Core.utility;
|
||||
/// </summary>
|
||||
public abstract class AbstractContextUtility : ContextAwareBase, IContextUtility
|
||||
{
|
||||
private ILogger _logger = null!;
|
||||
protected ILogger _logger = new NoopLoggerFactory().GetLogger(nameof(AbstractContextUtility));
|
||||
|
||||
/// <summary>
|
||||
/// 初始化上下文工具类
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user