@@ -110,7 +110,7 @@ public Parser(GeneratorExecutionContext context)
110110 /// <summary>
111111 /// Gets the set of logging classes that should be generated based on the discovered annotated interfaces.
112112 /// </summary>
113- public IEnumerable < LoggerClass > GetLogClasses ( List < InterfaceDeclarationSyntax > interfaces )
113+ public IEnumerable < LoggerClass > GetLogClasses ( List < TypeDeclarationSyntax > types )
114114 {
115115 var logExtensionsAttribute = _compilation . GetTypeByMetadataName ( "Microsoft.Extensions.Logging.LoggerExtensionsAttribute" ) ;
116116 if ( logExtensionsAttribute is null )
@@ -140,9 +140,9 @@ public IEnumerable<LoggerClass> GetLogClasses(List<InterfaceDeclarationSyntax> i
140140 yield break ;
141141 }
142142
143- foreach ( var iface in interfaces )
143+ foreach ( var typeDef in types )
144144 {
145- foreach ( var al in iface . AttributeLists )
145+ foreach ( var al in typeDef . AttributeLists )
146146 {
147147 foreach ( var a in al . Attributes )
148148 {
@@ -153,13 +153,13 @@ public IEnumerable<LoggerClass> GetLogClasses(List<InterfaceDeclarationSyntax> i
153153 {
154154 // determine the namespace the interface is declared in, if any
155155 NamespaceDeclarationSyntax ? ns = null ;
156- if ( iface . Parent != null )
156+ if ( typeDef . Parent != null )
157157 {
158- ns = iface . Parent as NamespaceDeclarationSyntax ;
159- if ( ns == null && iface . Parent is not CompilationUnitSyntax )
158+ ns = typeDef . Parent as NamespaceDeclarationSyntax ;
159+ if ( ns == null && typeDef . Parent is not CompilationUnitSyntax )
160160 {
161161 // since this generator doesn't know how to generate a nested type...
162- Diag ( ErrorNestedType , iface . Identifier . GetLocation ( ) ) ;
162+ Diag ( ErrorNestedType , typeDef . Identifier . GetLocation ( ) ) ;
163163 }
164164 }
165165
@@ -173,42 +173,48 @@ public IEnumerable<LoggerClass> GetLogClasses(List<InterfaceDeclarationSyntax> i
173173 }
174174
175175 // if no name was specified, try to derive it from the interface name
176- var ifaceName = iface . Identifier . ToString ( ) ;
176+ var ifaceName = typeDef . Identifier . ToString ( ) ;
177177 if ( name == null )
178178 {
179- if ( ifaceName [ 0 ] == 'I' )
179+ if ( typeDef is InterfaceDeclarationSyntax iface )
180180 {
181- // strip the leading I
182- name = ifaceName . Substring ( 1 ) ;
181+ if ( ifaceName [ 0 ] == 'I' && ifaceName . Length > 1 )
182+ {
183+ name = ifaceName . Substring ( 1 ) ;
184+ }
185+ else
186+ {
187+ name = ifaceName + "Extensions" ;
188+ }
183189 }
184190 else
185191 {
186- // fail
187- name = string . Empty ;
192+ name = typeDef . Identifier . ToString ( ) ;
188193 }
189194 }
190195
191196 var lc = new LoggerClass
192197 {
193198 Namespace = ns ? . Name . ToString ( ) ,
194199 Name = name ,
195- OriginalInterfaceName = iface . Identifier . ToString ( ) ,
196- AccessModifiers = iface . Modifiers . ToString ( ) ,
197- Documentation = GetDocs ( iface ) ,
200+ OriginalInterfaceName = typeDef . Identifier . ToString ( ) ,
201+ AccessModifiers = typeDef . Modifiers . ToString ( ) ,
202+ Documentation = GetDocs ( typeDef ) ,
203+ IsInterface = typeDef is InterfaceDeclarationSyntax
198204 } ;
199205
200206 if ( string . IsNullOrWhiteSpace ( lc . Name ) )
201207 {
202208 Diag ( ErrorInvalidTypeName , a . GetLocation ( ) , ifaceName ) ;
203209 }
204210
205- if ( iface . Arity > 0 )
211+ if ( typeDef . Arity > 0 )
206212 {
207- Diag ( ErrorInterfaceGeneric , iface . GetLocation ( ) ) ;
213+ Diag ( ErrorInterfaceGeneric , typeDef . GetLocation ( ) ) ;
208214 }
209215
210216 var ids = new HashSet < string > ( ) ;
211- foreach ( var method in iface . Members . Where ( m => m . IsKind ( SyntaxKind . MethodDeclaration ) ) . OfType < MethodDeclarationSyntax > ( ) )
217+ foreach ( var method in typeDef . Members . Where ( m => m . IsKind ( SyntaxKind . MethodDeclaration ) ) . OfType < MethodDeclarationSyntax > ( ) )
212218 {
213219 foreach ( var mal in method . AttributeLists )
214220 {
@@ -289,6 +295,12 @@ public IEnumerable<LoggerClass> GetLogClasses(List<InterfaceDeclarationSyntax> i
289295 Type = p . Type ! . ToString ( ) ,
290296 IsExceptionType = IsBaseOrIdentity ( pSymbol , exSymbol ) ,
291297 } ;
298+
299+ if ( lp . Type . EndsWith ( "ILogger" , StringComparison . Ordinal ) )
300+ {
301+ continue ;
302+ }
303+
292304 lm . Parameters . Add ( lp ) ;
293305
294306 if ( lp . Name . StartsWith ( "__" , StringComparison . Ordinal ) )
@@ -394,6 +406,7 @@ private class LoggerClass
394406 public string AccessModifiers = string . Empty ;
395407 public List < LoggerMethod > Methods = new ( ) ;
396408 public string Documentation = string . Empty ;
409+ public bool IsInterface { get ; set ; }
397410 }
398411
399412 // A log method in a logging class
0 commit comments