Skip to content

Commit

Permalink
Ignore Enrich.With<> / With(params) since it cannot be expressed in c…
Browse files Browse the repository at this point in the history
…onfig
  • Loading branch information
Suchiman committed Sep 20, 2016
1 parent 4a6ac6b commit 5945d6f
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
66 changes: 66 additions & 0 deletions SerilogAnalyzer/SerilogAnalyzer.Test/RefactoringTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,72 @@ public object GetFormat(Type formatType)
{
return null;
}
}";
VerifyCSharpRefactoring(test, fixtest, "Show appsettings.json config");
}

[TestMethod]
public void TestEnrichWithEnricher()
{
var test = @"
using Serilog;
using System;
class TypeName
{
public static void Test()
{
ILogger test = [|new LoggerConfiguration()
.Enrich.With(null)
.CreateLogger()|];
}
}";

var fixtest = @"
using Serilog;
using System;
class TypeName
{
public static void Test()
{
ILogger test = new LoggerConfiguration()
.Enrich.With(null)
.CreateLogger();
}
}";
VerifyCSharpRefactoring(test, fixtest, "Show appsettings.json config");
}

[TestMethod]
public void TestEnrichWithGenericEnricher()
{
var test = @"
using Serilog;
using System;
class TypeName
{
public static void Test()
{
ILogger test = [|new LoggerConfiguration()
.Enrich.With<Test>()
.CreateLogger()|];
}
}";

var fixtest = @"
using Serilog;
using System;
class TypeName
{
public static void Test()
{
ILogger test = new LoggerConfiguration()
.Enrich.With<Test>()
.CreateLogger();
}
}";
VerifyCSharpRefactoring(test, fixtest, "Show appsettings.json config");
}
Expand Down
5 changes: 5 additions & 0 deletions SerilogAnalyzer/SerilogAnalyzer/CodeRefactoringProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@ private static LoggerConfiguration GetLoggerConfigurationFromSyntax(CodeRefactor
configuration.EnrichWithProperty[key] = value;
}
}
else if (((invokedMethod.Name as GenericNameSyntax)?.Identifier.ToString() ?? invokedMethod.Name.ToString()) == "With")
{
// configuration cannot express Enrich.With(new SomeEnricher()) or Enrich.With<SomeEnricher>()
continue;
}
else
{
var method = GetExtensibleMethod(semanticModel, invokedMethod, context.CancellationToken);
Expand Down

0 comments on commit 5945d6f

Please sign in to comment.