diff --git a/Directory.Build.props b/Directory.Build.props index ca6181f..d913e1a 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -2,7 +2,7 @@ - 2022.3.1 + 2022.3.2 diff --git a/src/.run/Pack ReSharper.run.xml b/src/.run/Pack ReSharper.run.xml new file mode 100644 index 0000000..adbc4b3 --- /dev/null +++ b/src/.run/Pack ReSharper.run.xml @@ -0,0 +1,20 @@ + + + + \ No newline at end of file diff --git a/src/.run/Pack Rider.run.xml b/src/.run/Pack Rider.run.xml new file mode 100644 index 0000000..e7fa3db --- /dev/null +++ b/src/.run/Pack Rider.run.xml @@ -0,0 +1,20 @@ + + + + \ No newline at end of file diff --git a/src/.run/Test ReSharper.run.xml b/src/.run/Test ReSharper.run.xml new file mode 100644 index 0000000..86025aa --- /dev/null +++ b/src/.run/Test ReSharper.run.xml @@ -0,0 +1,20 @@ + + + + \ No newline at end of file diff --git a/src/.run/Test Rider.run.xml b/src/.run/Test Rider.run.xml new file mode 100644 index 0000000..31afe0f --- /dev/null +++ b/src/.run/Test Rider.run.xml @@ -0,0 +1,20 @@ + + + + \ No newline at end of file diff --git a/src/ReSharper.Structured.Logging/Analyzer/PropertiesNamingAnalyzer.cs b/src/ReSharper.Structured.Logging/Analyzer/PropertiesNamingAnalyzer.cs index c3ff322..75a4bf1 100644 --- a/src/ReSharper.Structured.Logging/Analyzer/PropertiesNamingAnalyzer.cs +++ b/src/ReSharper.Structured.Logging/Analyzer/PropertiesNamingAnalyzer.cs @@ -100,7 +100,9 @@ private void CheckPropertiesInContext( } var propertyArgument = element.ArgumentList.Arguments[0]; - var propertyName = propertyArgument.Value?.ConstantValue.StringValue; + + var propertyName = string.Empty; + propertyArgument.Value?.ConstantValue.IsString(out propertyName); if (string.IsNullOrEmpty(propertyName)) { return; diff --git a/test/data/Analyzers/PropertiesNamingAnalyzer/SerilogContextInterpolatedStringProperty.cs b/test/data/Analyzers/PropertiesNamingAnalyzer/SerilogContextInterpolatedStringProperty.cs new file mode 100644 index 0000000..c68bd07 --- /dev/null +++ b/test/data/Analyzers/PropertiesNamingAnalyzer/SerilogContextInterpolatedStringProperty.cs @@ -0,0 +1,14 @@ +using Serilog; +using Serilog.Context; + +namespace ConsoleApp +{ + public static class Program + { + public static void Main() + { + var s = "world"; + LogContext.PushProperty($"Hello{s}", 1); + } + } +} diff --git a/test/data/Analyzers/PropertiesNamingAnalyzer/SerilogContextInterpolatedStringProperty.cs.gold b/test/data/Analyzers/PropertiesNamingAnalyzer/SerilogContextInterpolatedStringProperty.cs.gold new file mode 100644 index 0000000..eaa6d38 --- /dev/null +++ b/test/data/Analyzers/PropertiesNamingAnalyzer/SerilogContextInterpolatedStringProperty.cs.gold @@ -0,0 +1,16 @@ +using Serilog; +using Serilog.Context; + +namespace ConsoleApp +{ + public static class Program + { + public static void Main() + { + var s = "world"; + LogContext.PushProperty($"Hello{s}", 1); + } + } +} + +--------------------------------------------------------- diff --git a/test/src/Analyzer/PropertiesNamingAnalyzerTests.cs b/test/src/Analyzer/PropertiesNamingAnalyzerTests.cs index 09ed495..446f3ec 100644 --- a/test/src/Analyzer/PropertiesNamingAnalyzerTests.cs +++ b/test/src/Analyzer/PropertiesNamingAnalyzerTests.cs @@ -14,6 +14,8 @@ public class PropertiesNamingAnalyzerTests : MessageTemplateAnalyzerTestBase [Test] public void TestSerilogContextInvalidNamedProperty() => DoNamedTest2(); + [Test] public void TestSerilogContextInterpolatedStringProperty() => DoNamedTest2(); + [Test] public void TestSerilogInvalidNamedPropertyWithDot() => DoNamedTest2(); [Test] public void TestSerilogInvalidNamedPropertyWithSpace() => DoNamedTest2();