From 1e2f601407a72a37c9acaadef2589327b561af81 Mon Sep 17 00:00:00 2001 From: Thomas Trageser Date: Mon, 25 Mar 2013 21:00:08 +0000 Subject: [PATCH 1/2] Enhance ComponentScan logging messages --- .../AssemblyObjectDefinitionScanner.cs | 2 ++ .../Context/Attributes/AssemblyTypeScanner.cs | 18 ++++++++++++++---- .../TypeFilters/AssignableTypeFilter.cs | 11 +++++++++++ .../TypeFilters/AttributeTypeFilter.cs | 12 ++++++++++++ .../TypeFilters/RegexPatternTypeFilter.cs | 12 ++++++++++++ .../ComponentScanObjectDefinitionParser.cs | 19 ++++++++++++++++--- 6 files changed, 67 insertions(+), 7 deletions(-) diff --git a/src/Spring/Spring.Core/Context/Attributes/AssemblyObjectDefinitionScanner.cs b/src/Spring/Spring.Core/Context/Attributes/AssemblyObjectDefinitionScanner.cs index e6f0b9fe..36bd6636 100644 --- a/src/Spring/Spring.Core/Context/Attributes/AssemblyObjectDefinitionScanner.cs +++ b/src/Spring/Spring.Core/Context/Attributes/AssemblyObjectDefinitionScanner.cs @@ -70,6 +70,8 @@ namespace Spring.Context.Attributes { var definition = new ScannedGenericObjectDefinition(type, Defaults); string objectName = ObjectNameGenerator.GenerateObjectName(definition, registry); + + Logger.Debug(m => m("Register Type: {0} with object name '{1}'", type.FullName, objectName)); registry.RegisterObjectDefinition(objectName, definition); } } diff --git a/src/Spring/Spring.Core/Context/Attributes/AssemblyTypeScanner.cs b/src/Spring/Spring.Core/Context/Attributes/AssemblyTypeScanner.cs index 15ab0f9a..c553c5d1 100644 --- a/src/Spring/Spring.Core/Context/Attributes/AssemblyTypeScanner.cs +++ b/src/Spring/Spring.Core/Context/Attributes/AssemblyTypeScanner.cs @@ -179,6 +179,7 @@ namespace Spring.Context.Attributes { if (IsCompoundPredicateSatisfiedBy(type)) { + Logger.Debug(m => m("Satisfied Type: {0}", type.FullName)); types.Add(type); } } @@ -274,6 +275,7 @@ namespace Spring.Context.Attributes if (null != loadedAssembly) { + Logger.Debug(m => m("Add Assembly: {0}", loadedAssembly.FullName)); assemblies.Add(loadedAssembly); } } @@ -313,9 +315,12 @@ namespace Spring.Context.Attributes /// protected virtual IEnumerable ApplyAssemblyFiltersTo(IEnumerable assemblyCandidates) { - return - assemblyCandidates.Where(IsIncludedAssembly). - AsEnumerable(); + var filteredAssemblies = assemblyCandidates.Where(IsIncludedAssembly). + AsEnumerable(); + + Logger.Debug(m => m("Filtered Assemblies: {0}", StringUtils.ArrayToCommaDelimitedString(filteredAssemblies.ToArray()))); + + return filteredAssemblies; } /// @@ -351,7 +356,12 @@ namespace Spring.Context.Attributes /// protected virtual bool IsIncludedAssembly(Assembly assembly) { - return AssemblyInclusionPredicates.Any(include => include(assembly)); + bool result = AssemblyInclusionPredicates.Any(include => include(assembly)); + + if (result) + Logger.Debug(m => m("Include Assembly: {0}", assembly.FullName)); + + return result; } /// diff --git a/src/Spring/Spring.Core/Context/Attributes/TypeFilters/AssignableTypeFilter.cs b/src/Spring/Spring.Core/Context/Attributes/TypeFilters/AssignableTypeFilter.cs index 2c073144..76d5f967 100644 --- a/src/Spring/Spring.Core/Context/Attributes/TypeFilters/AssignableTypeFilter.cs +++ b/src/Spring/Spring.Core/Context/Attributes/TypeFilters/AssignableTypeFilter.cs @@ -52,5 +52,16 @@ namespace Spring.Context.Attributes.TypeFilters return (type.GetInterfaces().Any(i => i.Equals(RequiredType)) || RequiredType.Equals(type.BaseType)); } + /// + /// Returns a string that represents the current object. + /// + /// + /// A string that represents the current object. + /// + /// 2 + public override string ToString() + { + return string.Format("Required Type: {0}", RequiredType != null ? RequiredType.FullName : ""); + } } } diff --git a/src/Spring/Spring.Core/Context/Attributes/TypeFilters/AttributeTypeFilter.cs b/src/Spring/Spring.Core/Context/Attributes/TypeFilters/AttributeTypeFilter.cs index 22ad4642..d5343a58 100644 --- a/src/Spring/Spring.Core/Context/Attributes/TypeFilters/AttributeTypeFilter.cs +++ b/src/Spring/Spring.Core/Context/Attributes/TypeFilters/AttributeTypeFilter.cs @@ -52,5 +52,17 @@ namespace Spring.Context.Attributes.TypeFilters return (Attribute.GetCustomAttribute(type, RequiredType) != null); } + /// + /// Returns a string that represents the current object. + /// + /// + /// A string that represents the current object. + /// + /// 2 + public override string ToString() + { + return string.Format("Required Type: {0}", RequiredType != null ? RequiredType.FullName : ""); + } + } } diff --git a/src/Spring/Spring.Core/Context/Attributes/TypeFilters/RegexPatternTypeFilter.cs b/src/Spring/Spring.Core/Context/Attributes/TypeFilters/RegexPatternTypeFilter.cs index f4e5468b..0b26bd0a 100644 --- a/src/Spring/Spring.Core/Context/Attributes/TypeFilters/RegexPatternTypeFilter.cs +++ b/src/Spring/Spring.Core/Context/Attributes/TypeFilters/RegexPatternTypeFilter.cs @@ -49,5 +49,17 @@ namespace Spring.Context.Attributes.TypeFilters { return Regex.IsMatch(type.FullName, _pattern); } + + /// + /// Returns a string that represents the current object. + /// + /// + /// A string that represents the current object. + /// + /// 2 + public override string ToString() + { + return string.Format("Pattern: {0}", _pattern); + } } } diff --git a/src/Spring/Spring.Core/Context/Config/ComponentScanObjectDefinitionParser.cs b/src/Spring/Spring.Core/Context/Config/ComponentScanObjectDefinitionParser.cs index e63bae82..e4027bdf 100644 --- a/src/Spring/Spring.Core/Context/Config/ComponentScanObjectDefinitionParser.cs +++ b/src/Spring/Spring.Core/Context/Config/ComponentScanObjectDefinitionParser.cs @@ -102,6 +102,9 @@ namespace Spring.Context.Config foreach (var baseAssembly in baseAssemblies.Split(',')) { + if (Logger.IsDebugEnabled) + Logger.Debug("Start With Assembly Filter: " + baseAssembly); + scanner.WithAssemblyFilter(assy => assy.FullName.StartsWith(baseAssembly)); } } @@ -111,7 +114,10 @@ namespace Spring.Context.Config var nameGeneratorString = element.GetAttribute(NAME_GENERATOR_ATTRIBUTE); var nameGenerator = CustomTypeFactory.GetNameGenerator(nameGeneratorString); if (nameGenerator != null) + { + Logger.Debug(m => m("Use NameTable Generator: {0}", nameGeneratorString)); scanner.ObjectNameGenerator = nameGenerator; + } } private void ParseTypeFilters(AssemblyObjectDefinitionScanner scanner, XmlElement element) @@ -119,9 +125,17 @@ namespace Spring.Context.Config foreach (XmlNode node in element.ChildNodes) { if (node.Name.Contains(INCLUDE_FILTER_ELEMENT)) - scanner.WithIncludeFilter(CreateTypeFilter(node)); + { + var filter = CreateTypeFilter(node); + Logger.Debug(m => m("Inlude Filter: {0}", filter)); + scanner.WithIncludeFilter(filter); + } else if (node.Name.Contains(EXCLUDE_FILTER_ELEMENT)) - scanner.WithExcludeFilter(CreateTypeFilter(node)); + { + var filter = CreateTypeFilter(node); + Logger.Debug(m => m("Exclude Filter: {0}", filter)); + scanner.WithExcludeFilter(filter); + } } } @@ -154,6 +168,5 @@ namespace Spring.Context.Config throw new InvalidEnumArgumentException(string.Format("Filter type {0} is not defined", type)); } } - } } From 951b23209aba94ab6edcfe5fdf845c1c3968448d Mon Sep 17 00:00:00 2001 From: Thomas Trageser Date: Sun, 7 Apr 2013 00:19:28 +0100 Subject: [PATCH 2/2] Error because of using a wrong reference in lambda debig message --- .../Attributes/AssemblyObjectDefinitionScanner.cs | 3 ++- .../Context/Attributes/AssemblyTypeScanner.cs | 9 +++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Spring/Spring.Core/Context/Attributes/AssemblyObjectDefinitionScanner.cs b/src/Spring/Spring.Core/Context/Attributes/AssemblyObjectDefinitionScanner.cs index 36bd6636..da9acbf8 100644 --- a/src/Spring/Spring.Core/Context/Attributes/AssemblyObjectDefinitionScanner.cs +++ b/src/Spring/Spring.Core/Context/Attributes/AssemblyObjectDefinitionScanner.cs @@ -70,8 +70,9 @@ namespace Spring.Context.Attributes { var definition = new ScannedGenericObjectDefinition(type, Defaults); string objectName = ObjectNameGenerator.GenerateObjectName(definition, registry); + string fullname = type.FullName; - Logger.Debug(m => m("Register Type: {0} with object name '{1}'", type.FullName, objectName)); + Logger.Debug(m => m("Register Type: {0} with object name '{1}'", fullname, objectName)); registry.RegisterObjectDefinition(objectName, definition); } } diff --git a/src/Spring/Spring.Core/Context/Attributes/AssemblyTypeScanner.cs b/src/Spring/Spring.Core/Context/Attributes/AssemblyTypeScanner.cs index c553c5d1..30a4d62e 100644 --- a/src/Spring/Spring.Core/Context/Attributes/AssemblyTypeScanner.cs +++ b/src/Spring/Spring.Core/Context/Attributes/AssemblyTypeScanner.cs @@ -275,7 +275,9 @@ namespace Spring.Context.Attributes if (null != loadedAssembly) { - Logger.Debug(m => m("Add Assembly: {0}", loadedAssembly.FullName)); + string fullname = loadedAssembly.FullName; + Logger.Debug(m => m("Add Assembly: {0}", fullname)); + assemblies.Add(loadedAssembly); } } @@ -359,7 +361,10 @@ namespace Spring.Context.Attributes bool result = AssemblyInclusionPredicates.Any(include => include(assembly)); if (result) - Logger.Debug(m => m("Include Assembly: {0}", assembly.FullName)); + { + string fullname = assembly.FullName; + Logger.Debug(m => m("Include Assembly: {0}", fullname)); + } return result; }