From c377fd95446b4bc74c31a5a3ce89718eb05e7ebb Mon Sep 17 00:00:00 2001 From: maliming Date: Thu, 9 Apr 2026 14:23:37 +0800 Subject: [PATCH] Refactor InitLogger to flush all categories and address review feedback - WriteInitLogs now uses ILoggerFactory to flush all InitLogger categories with their original category name instead of only flushing AbpApplicationBase - Add CategoryName to AbpInitLogEntry, recorded automatically by DefaultInitLogger using typeof(T).FullName - Add GetAllEntries/ClearAllEntries to IInitLoggerFactory interface - Add GetReferencedAssemblies filter to skip non-ABP assemblies - Handle ReflectionTypeLoadException separately from other exceptions - Add CategoryName null/empty fallback in WriteInitLogs - Skip DisablePropertyInjection types from orphaned module detection --- .../Autofac/Builder/AbpRegistrationBuilderExtensions.cs | 2 +- .../Extensions/DependencyInjection/AutofacRegistration.cs | 4 ++++ framework/src/Volo.Abp.Core/Volo/Abp/AbpApplicationBase.cs | 5 ++++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/framework/src/Volo.Abp.Autofac/Autofac/Builder/AbpRegistrationBuilderExtensions.cs b/framework/src/Volo.Abp.Autofac/Autofac/Builder/AbpRegistrationBuilderExtensions.cs index db910d21e0..2bf2d30605 100644 --- a/framework/src/Volo.Abp.Autofac/Autofac/Builder/AbpRegistrationBuilderExtensions.cs +++ b/framework/src/Volo.Abp.Autofac/Autofac/Builder/AbpRegistrationBuilderExtensions.cs @@ -112,7 +112,7 @@ public static class AbpRegistrationBuilderExtensions registrationBuilder = registrationBuilder.PropertiesAutowired(new AbpPropertySelector(false)); } } - else + else if (implementationType.GetCustomAttributes(typeof(DisablePropertyInjectionAttribute), true).IsNullOrEmpty()) { nonModuleAssemblies?.Add(implementationType.Assembly); } diff --git a/framework/src/Volo.Abp.Autofac/Autofac/Extensions/DependencyInjection/AutofacRegistration.cs b/framework/src/Volo.Abp.Autofac/Autofac/Extensions/DependencyInjection/AutofacRegistration.cs index f194e18775..11216e39ec 100644 --- a/framework/src/Volo.Abp.Autofac/Autofac/Extensions/DependencyInjection/AutofacRegistration.cs +++ b/framework/src/Volo.Abp.Autofac/Autofac/Extensions/DependencyInjection/AutofacRegistration.cs @@ -417,6 +417,10 @@ public static class AutofacRegistration { types = assembly.GetTypes(); } + catch (ReflectionTypeLoadException ex) + { + types = ex.Types.Where(t => t != null).ToArray()!; + } catch (Exception) { continue; diff --git a/framework/src/Volo.Abp.Core/Volo/Abp/AbpApplicationBase.cs b/framework/src/Volo.Abp.Core/Volo/Abp/AbpApplicationBase.cs index f91d251d2d..6002c005b7 100644 --- a/framework/src/Volo.Abp.Core/Volo/Abp/AbpApplicationBase.cs +++ b/framework/src/Volo.Abp.Core/Volo/Abp/AbpApplicationBase.cs @@ -138,7 +138,10 @@ public abstract class AbpApplicationBase : IAbpApplication foreach (var entry in initLoggerFactory.GetAllEntries()) { - var logger = loggerFactory.CreateLogger(entry.CategoryName); + var categoryName = string.IsNullOrEmpty(entry.CategoryName) + ? nameof(AbpApplicationBase) + : entry.CategoryName; + var logger = loggerFactory.CreateLogger(categoryName); logger.Log(entry.LogLevel, entry.EventId, entry.State, entry.Exception, entry.Formatter); }