mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-03-24 20:34:29 +08:00
refactor(logging): 优化日志记录器的类型名称获取方式
- 修复了Architecture模块安装时的日志记录器类型名称 - 统一了IocContainer中日志记录器的类型名称获取逻辑 - 重构了AbstractSystem中日志记录器的类型名称处理 - 改进了AbstractContextUtility中日志记录器的类型名称获取 - 通过变量缓存避免重复调用GetType().Name提高性能
This commit is contained in:
parent
e543ef9baf
commit
333cefa84e
@ -72,7 +72,7 @@ public abstract class Architecture(
|
|||||||
public void InstallModule(IArchitectureModule module)
|
public void InstallModule(IArchitectureModule module)
|
||||||
{
|
{
|
||||||
var logger =
|
var logger =
|
||||||
LoggerFactoryResolver.Provider.CreateLogger(nameof(GetType));
|
LoggerFactoryResolver.Provider.CreateLogger(nameof(module));
|
||||||
logger.Debug($"Installing module: {module.GetType().Name}.Module");
|
logger.Debug($"Installing module: {module.GetType().Name}.Module");
|
||||||
RegisterLifecycleHook(module);
|
RegisterLifecycleHook(module);
|
||||||
Container.RegisterPlurality(module);
|
Container.RegisterPlurality(module);
|
||||||
|
|||||||
@ -56,7 +56,7 @@ public class IocContainer : ContextAwareBase, IIocContainer
|
|||||||
protected override void OnContextReady()
|
protected override void OnContextReady()
|
||||||
{
|
{
|
||||||
_logger =
|
_logger =
|
||||||
LoggerFactoryResolver.Provider.CreateLogger(nameof(GetType));
|
LoggerFactoryResolver.Provider.CreateLogger(nameof(IocContainer));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@ -19,12 +19,13 @@ public abstract class AbstractSystem : ContextAwareBase, ISystem
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
void ISystem.Init()
|
void ISystem.Init()
|
||||||
{
|
{
|
||||||
_logger = LoggerFactoryResolver.Provider.CreateLogger(nameof(GetType));
|
var name = GetType().Name;
|
||||||
_logger.Debug($"Initializing system: {GetType().Name}");
|
_logger = LoggerFactoryResolver.Provider.CreateLogger(name);
|
||||||
|
_logger.Debug($"Initializing system: {name}");
|
||||||
|
|
||||||
OnInit();
|
OnInit();
|
||||||
|
|
||||||
_logger.Info($"System initialized: {GetType().Name}");
|
_logger.Info($"System initialized: {name}");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@ -18,15 +18,16 @@ public abstract class AbstractContextUtility : ContextAwareBase, IContextUtility
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
void IContextUtility.Init()
|
void IContextUtility.Init()
|
||||||
{
|
{
|
||||||
|
var name = GetType().Name;
|
||||||
// 获取上下文中的日志记录器
|
// 获取上下文中的日志记录器
|
||||||
Logger = LoggerFactoryResolver.Provider.CreateLogger(nameof(GetType));
|
Logger = LoggerFactoryResolver.Provider.CreateLogger(name);
|
||||||
Logger.Debug($"Initializing Context Utility: {GetType().Name}");
|
Logger.Debug($"Initializing Context Utility: {name}");
|
||||||
|
|
||||||
// 执行子类实现的初始化逻辑
|
// 执行子类实现的初始化逻辑
|
||||||
OnInit();
|
OnInit();
|
||||||
|
|
||||||
// 记录初始化完成信息
|
// 记录初始化完成信息
|
||||||
Logger.Info($"Context Utility initialized: {GetType().Name}");
|
Logger.Info($"Context Utility initialized: {name}");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user