diff --git a/SerilogAnalyzer/SerilogAnalyzer/DiagnosticAnalyzer.cs b/SerilogAnalyzer/SerilogAnalyzer/DiagnosticAnalyzer.cs index c6ef7ce..c334de6 100644 --- a/SerilogAnalyzer/SerilogAnalyzer/DiagnosticAnalyzer.cs +++ b/SerilogAnalyzer/SerilogAnalyzer/DiagnosticAnalyzer.cs @@ -77,15 +77,16 @@ public class SerilogAnalyzerAnalyzer : DiagnosticAnalyzer public override ImmutableArray SupportedDiagnostics => ImmutableArray.Create(ExceptionRule, TemplateRule, PropertyBindingRule, ConstantMessageTemplateRule, UniquePropertyNameRule, PascalPropertyNameRule, DestructureAnonymousObjectsRule, UseCorrectContextualLoggerRule); - private const string ILogger = "Serilog.ILogger"; - private const string ForContext = "ForContext"; + protected virtual string ILogger => "Serilog.ILogger"; + protected virtual string ForContext => "ForContext"; + protected virtual string LoggerMethodAttribute => "Serilog.Core.MessageTemplateFormatMethodAttribute"; public override void Initialize(AnalysisContext context) { context.RegisterSyntaxNodeAction(AnalyzeSymbol, SyntaxKind.InvocationExpression); } - private static void AnalyzeSymbol(SyntaxNodeAnalysisContext context) + private void AnalyzeSymbol(SyntaxNodeAnalysisContext context) { var invocation = context.Node as InvocationExpressionSyntax; var info = context.SemanticModel.GetSymbolInfo(invocation, context.CancellationToken); @@ -96,7 +97,7 @@ private static void AnalyzeSymbol(SyntaxNodeAnalysisContext context) } // is serilog even present in the compilation? - var messageTemplateAttribute = context.SemanticModel.Compilation.GetTypeByMetadataName("Serilog.Core.MessageTemplateFormatMethodAttribute"); + var messageTemplateAttribute = context.SemanticModel.Compilation.GetTypeByMetadataName(LoggerMethodAttribute); if (messageTemplateAttribute == null) { return; @@ -268,7 +269,7 @@ bool HasConventionalExceptionParameter(IMethodSymbol methodSymbol) } } - private static void CheckForContextCorrectness(ref SyntaxNodeAnalysisContext context, InvocationExpressionSyntax invocation, IMethodSymbol method) + private void CheckForContextCorrectness(ref SyntaxNodeAnalysisContext context, InvocationExpressionSyntax invocation, IMethodSymbol method) { // is this really a field / property? var decl = invocation.Ancestors().OfType().FirstOrDefault();