Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow namespaces to be changed to support use cases with wrapper classes #53

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions SerilogAnalyzer/SerilogAnalyzer/DiagnosticAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,16 @@ public class SerilogAnalyzerAnalyzer : DiagnosticAnalyzer

public override ImmutableArray<DiagnosticDescriptor> 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);
Expand All @@ -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;
Expand Down Expand Up @@ -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<MemberDeclarationSyntax>().FirstOrDefault();
Expand Down