From fc4b4f2244e8ac640a1fdd6cd7cfa1e5da184fd2 Mon Sep 17 00:00:00 2001 From: Thibaud Desodt Date: Mon, 16 Oct 2017 07:30:00 +0200 Subject: [PATCH 01/10] Removed redundant qualifier --- test/Serilog.Tests/Settings/SettingValueConversionsTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/Serilog.Tests/Settings/SettingValueConversionsTests.cs b/test/Serilog.Tests/Settings/SettingValueConversionsTests.cs index 9dacbe050..17d2cfcfc 100644 --- a/test/Serilog.Tests/Settings/SettingValueConversionsTests.cs +++ b/test/Serilog.Tests/Settings/SettingValueConversionsTests.cs @@ -33,8 +33,8 @@ public void EmptyStringValuesConvertToNullIfTargetIsNullable() [Fact] public void ValuesConvertToNullableTimeSpan() { - var result = (System.TimeSpan?)SettingValueConversions.ConvertToType("00:01:00", typeof(System.TimeSpan?)); - Assert.Equal(System.TimeSpan.FromMinutes(1), result); + var result = (TimeSpan?)SettingValueConversions.ConvertToType("00:01:00", typeof(TimeSpan?)); + Assert.Equal(TimeSpan.FromMinutes(1), result); } [Fact] From 3377bf33e8fe30bcfbefd34862f664942ae187a9 Mon Sep 17 00:00:00 2001 From: Thibaud Desodt Date: Mon, 16 Oct 2017 07:31:48 +0200 Subject: [PATCH 02/10] Remove unused declared variables --- .../MethodOverloadConventionTests.cs | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/test/Serilog.Tests/MethodOverloadConventionTests.cs b/test/Serilog.Tests/MethodOverloadConventionTests.cs index 1c03f55f6..8e8300823 100644 --- a/test/Serilog.Tests/MethodOverloadConventionTests.cs +++ b/test/Serilog.Tests/MethodOverloadConventionTests.cs @@ -305,9 +305,7 @@ public void ValidateIsEnabledMethods(Type loggerType) Assert.Equal(parameter.Name, "level"); Assert.Equal(parameter.ParameterType, typeof(LogEventLevel)); - CollectingSink sink; - - var logger = GetLogger(loggerType, out sink, LogEventLevel.Information); + var logger = GetLogger(loggerType, out _, LogEventLevel.Information); var falseResult = InvokeMethod(method, logger, new object[] { LogEventLevel.Verbose }); @@ -761,10 +759,7 @@ static void InvokeConventionMethod( static void InvokeConventionMethod(MethodInfo method, Type[] typeArgs, object[] parameters) { - CollectingSink sink; - LogEventLevel level; - - InvokeConventionMethod(method, typeArgs, parameters, out level, out sink); + InvokeConventionMethod(method, typeArgs, parameters, out _, out _); } static void InvokeConventionMethodAndTest(MethodInfo method, Type[] typeArgs, object[] parameters) @@ -901,9 +896,7 @@ static void EvaluateSingleResult(LogEventLevel level, CollectingSink results) static ILogger GetLogger(Type loggerType) { - CollectingSink sink; - - return GetLogger(loggerType, out sink); + return GetLogger(loggerType, out _); } static ILogger GetLogger(Type loggerType, out CollectingSink sink, LogEventLevel level = LogEventLevel.Verbose) @@ -940,4 +933,4 @@ static ILogger GetLogger(Type loggerType, out CollectingSink sink, LogEventLevel throw new ArgumentException($"Logger Type of {loggerType} is not supported"); } } -} \ No newline at end of file +} From 4fd5b26bae515a3456ce2f05ed169c31c79733c2 Mon Sep 17 00:00:00 2001 From: Thibaud Desodt Date: Mon, 16 Oct 2017 07:38:20 +0200 Subject: [PATCH 03/10] ReSharper : changed "Redundant Argument Default value" inspection severity from Warning to Suggestion --- Serilog.sln.DotSettings | 1 + 1 file changed, 1 insertion(+) diff --git a/Serilog.sln.DotSettings b/Serilog.sln.DotSettings index a84b8ae38..5fe3d28ac 100644 --- a/Serilog.sln.DotSettings +++ b/Serilog.sln.DotSettings @@ -50,6 +50,7 @@ WARNING HINT ERROR + SUGGESTION ERROR ERROR ERROR From 33d07a8282116faba336a89cdfc52a809437132d Mon Sep 17 00:00:00 2001 From: Thibaud Desodt Date: Mon, 16 Oct 2017 07:43:21 +0200 Subject: [PATCH 04/10] Get rid of "possible multiple enumerations" warning --- src/Serilog/Settings/KeyValuePairs/KeyValuePairSettings.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Serilog/Settings/KeyValuePairs/KeyValuePairSettings.cs b/src/Serilog/Settings/KeyValuePairs/KeyValuePairSettings.cs index b9ec1f059..69c619efd 100644 --- a/src/Serilog/Settings/KeyValuePairs/KeyValuePairSettings.cs +++ b/src/Serilog/Settings/KeyValuePairs/KeyValuePairSettings.cs @@ -148,7 +148,7 @@ where matchCallables.IsMatch(wt.Key) if (callableDirectives.Any()) { - var configurationAssemblies = LoadConfigurationAssemblies(directives); + var configurationAssemblies = LoadConfigurationAssemblies(directives).ToList(); foreach (var receiverGroup in callableDirectives.GroupBy(d => d.ReceiverType)) { From ebf548c830cc1c5c2d75fa38d25e5367b048c014 Mon Sep 17 00:00:00 2001 From: Thibaud Desodt Date: Mon, 16 Oct 2017 07:43:44 +0200 Subject: [PATCH 05/10] Get rid of 'hiding field' warning --- test/Serilog.Tests/Capturing/PropertyValueConverterTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/Serilog.Tests/Capturing/PropertyValueConverterTests.cs b/test/Serilog.Tests/Capturing/PropertyValueConverterTests.cs index 6534a35ef..bea70a67b 100644 --- a/test/Serilog.Tests/Capturing/PropertyValueConverterTests.cs +++ b/test/Serilog.Tests/Capturing/PropertyValueConverterTests.cs @@ -24,7 +24,7 @@ public class PropertyValueConverterTests [Fact] public async Task MaximumDepthIsEffectiveAndThreadSafe() { - var _converter = new PropertyValueConverter(3, 1000, 1000, Enumerable.Empty(), Enumerable.Empty(), false); + var converter = new PropertyValueConverter(3, 1000, 1000, Enumerable.Empty(), Enumerable.Empty(), false); var barrier = new Barrier(participantCount: 3); @@ -63,7 +63,7 @@ void DoThreadTest(object logObject, Action assertAction) { barrier.SignalAndWait(); - var propValue = _converter.CreatePropertyValue(logObject, true); + var propValue = converter.CreatePropertyValue(logObject, true); Assert.IsType(propValue); From 4c231f2ab98e5b6923c1ea7347b92c2f1e2df43a Mon Sep 17 00:00:00 2001 From: Thibaud Desodt Date: Mon, 16 Oct 2017 07:44:16 +0200 Subject: [PATCH 06/10] Get rid of ParameterOnlyUsedForPreconditionCheck --- test/Serilog.Tests/MethodOverloadConventionTests.cs | 2 ++ test/Serilog.Tests/Parsing/MessageTemplateParserTests.cs | 1 + 2 files changed, 3 insertions(+) diff --git a/test/Serilog.Tests/MethodOverloadConventionTests.cs b/test/Serilog.Tests/MethodOverloadConventionTests.cs index 8e8300823..523ec05ba 100644 --- a/test/Serilog.Tests/MethodOverloadConventionTests.cs +++ b/test/Serilog.Tests/MethodOverloadConventionTests.cs @@ -501,6 +501,7 @@ void ForContextMethod4(MethodInfo method) TestForContextResult(method, logger, normalResult: enrichedLogger); } + // ReSharper disable once ParameterOnlyUsedForPreconditionCheck.Local void TestForContextResult(MethodInfo method, ILogger logger, object normalResult) { Assert.NotNull(normalResult); @@ -884,6 +885,7 @@ static object InvokeMethod( return method.Invoke(instance, parameters); } + // ReSharper disable once ParameterOnlyUsedForPreconditionCheck.Local static void EvaluateSingleResult(LogEventLevel level, CollectingSink results) { //evaluate single log event diff --git a/test/Serilog.Tests/Parsing/MessageTemplateParserTests.cs b/test/Serilog.Tests/Parsing/MessageTemplateParserTests.cs index fdbe8de05..9e68fd29c 100644 --- a/test/Serilog.Tests/Parsing/MessageTemplateParserTests.cs +++ b/test/Serilog.Tests/Parsing/MessageTemplateParserTests.cs @@ -11,6 +11,7 @@ static MessageTemplateToken[] Parse(string messsageTemplate) return new MessageTemplateParser().Parse(messsageTemplate).Tokens.ToArray(); } + // ReSharper disable once ParameterOnlyUsedForPreconditionCheck.Local static void AssertParsedAs(string message, params MessageTemplateToken[] messageTemplateTokens) { var parsed = Parse(message); From af0d217d9e4188a29122af6b4a3d8bc448c97768 Mon Sep 17 00:00:00 2001 From: Thibaud Desodt Date: Mon, 16 Oct 2017 07:45:01 +0200 Subject: [PATCH 07/10] Get rid of HeuristicUnreachableCode warning --- test/Serilog.Tests/Settings/KeyValuePairSettingsTests.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/Serilog.Tests/Settings/KeyValuePairSettingsTests.cs b/test/Serilog.Tests/Settings/KeyValuePairSettingsTests.cs index 91c1da789..9b7e7f9fd 100644 --- a/test/Serilog.Tests/Settings/KeyValuePairSettingsTests.cs +++ b/test/Serilog.Tests/Settings/KeyValuePairSettingsTests.cs @@ -313,12 +313,14 @@ public void LoggingLevelSwitchCanBeUsedForMinimumLevelOverrides() systemLogger.Write(Some.WarningEvent()); Assert.False(evt is null, "LoggingLevelSwitch initial level was Warning for logger System.*. It should log Warning messages for SourceContext System.Bar"); + // ReSharper disable HeuristicUnreachableCode evt = null; var controlSwitch = DummyWithLevelSwitchSink.ControlLevelSwitch; controlSwitch.MinimumLevel = LogEventLevel.Information; systemLogger.Write(Some.InformationEvent()); Assert.False(evt is null, "LoggingLevelSwitch level was changed to Information for logger System.*. It should now log Information events for SourceContext System.Bar."); + // ReSharper restore HeuristicUnreachableCode } } From 2f71498bc5a7778da4625ac3635ae423433d11d0 Mon Sep 17 00:00:00 2001 From: Thibaud Desodt Date: Mon, 16 Oct 2017 07:51:21 +0200 Subject: [PATCH 08/10] Get rid of ThreadStaticFieldHasInitializer warnings --- test/TestDummies/DummyRollingFileAuditSink.cs | 2 ++ test/TestDummies/DummyRollingFileSink.cs | 2 ++ test/TestDummies/DummyWithLevelSwitchSink.cs | 2 ++ test/TestDummies/DummyWrappingSink.cs | 4 +++- 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/test/TestDummies/DummyRollingFileAuditSink.cs b/test/TestDummies/DummyRollingFileAuditSink.cs index 3a8355a8d..e8618d026 100644 --- a/test/TestDummies/DummyRollingFileAuditSink.cs +++ b/test/TestDummies/DummyRollingFileAuditSink.cs @@ -8,7 +8,9 @@ namespace TestDummies public class DummyRollingFileAuditSink : ILogEventSink { [ThreadStatic] + // ReSharper disable ThreadStaticFieldHasInitializer public static List Emitted = new List(); + // ReSharper restore ThreadStaticFieldHasInitializer public void Emit(LogEvent logEvent) { diff --git a/test/TestDummies/DummyRollingFileSink.cs b/test/TestDummies/DummyRollingFileSink.cs index 5e6bde88b..bc98ed219 100644 --- a/test/TestDummies/DummyRollingFileSink.cs +++ b/test/TestDummies/DummyRollingFileSink.cs @@ -8,7 +8,9 @@ namespace TestDummies public class DummyRollingFileSink : ILogEventSink { [ThreadStatic] + // ReSharper disable ThreadStaticFieldHasInitializer public static List Emitted = new List(); + // ReSharper restore ThreadStaticFieldHasInitializer public void Emit(LogEvent logEvent) { diff --git a/test/TestDummies/DummyWithLevelSwitchSink.cs b/test/TestDummies/DummyWithLevelSwitchSink.cs index 707574ce1..4e1d76fc3 100644 --- a/test/TestDummies/DummyWithLevelSwitchSink.cs +++ b/test/TestDummies/DummyWithLevelSwitchSink.cs @@ -16,7 +16,9 @@ public DummyWithLevelSwitchSink(LoggingLevelSwitch loggingControlLevelSwitch) public static LoggingLevelSwitch ControlLevelSwitch; [ThreadStatic] + // ReSharper disable ThreadStaticFieldHasInitializer public static List Emitted = new List(); + // ReSharper restore ThreadStaticFieldHasInitializer public void Emit(LogEvent logEvent) { diff --git a/test/TestDummies/DummyWrappingSink.cs b/test/TestDummies/DummyWrappingSink.cs index 9d7f96681..cd15d8c33 100644 --- a/test/TestDummies/DummyWrappingSink.cs +++ b/test/TestDummies/DummyWrappingSink.cs @@ -8,7 +8,9 @@ namespace TestDummies public class DummyWrappingSink : ILogEventSink { [ThreadStatic] + // ReSharper disable ThreadStaticFieldHasInitializer public static List Emitted = new List(); + // ReSharper restore ThreadStaticFieldHasInitializer private readonly ILogEventSink _sink; @@ -23,4 +25,4 @@ public void Emit(LogEvent logEvent) _sink.Emit(logEvent); } } -} \ No newline at end of file +} From abd9562d706a5b3ebfe56488aa006aa6c68ef47e Mon Sep 17 00:00:00 2001 From: Thibaud Desodt Date: Mon, 16 Oct 2017 07:54:27 +0200 Subject: [PATCH 09/10] Removed a few AssignNullToNotNullAttribute warnings in tests --- test/Serilog.Tests/Context/LogContextTests.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/Serilog.Tests/Context/LogContextTests.cs b/test/Serilog.Tests/Context/LogContextTests.cs index 7fc0b62df..3e46c1f00 100644 --- a/test/Serilog.Tests/Context/LogContextTests.cs +++ b/test/Serilog.Tests/Context/LogContextTests.cs @@ -31,7 +31,9 @@ static LogContextTests() public LogContextTests() { #if REMOTING + // ReSharper disable AssignNullToNotNullAttribute CallContext.LogicalSetData(typeof(LogContext).FullName, null); + // ReSharper restore AssignNullToNotNullAttribute #endif } @@ -266,7 +268,9 @@ public void DoesNotPreventCrossDomainCalls() { domain = AppDomain.CreateDomain("LogContextTests", null, AppDomain.CurrentDomain.SetupInformation); + // ReSharper disable AssignNullToNotNullAttribute var callable = (RemotelyCallable)domain.CreateInstanceAndUnwrap(typeof(RemotelyCallable).Assembly.FullName, typeof(RemotelyCallable).FullName); + // ReSharper restore AssignNullToNotNullAttribute using (LogContext.PushProperty("Anything", 1001)) Assert.True(callable.IsCallable()); @@ -381,4 +385,4 @@ public bool IsCallable() } } #endif -} \ No newline at end of file +} From f41eaf1b07a6ebf77f1f60fb41a1d6cbc558bd56 Mon Sep 17 00:00:00 2001 From: Thibaud Desodt Date: Tue, 17 Oct 2017 20:58:23 +0200 Subject: [PATCH 10/10] Added comments to ignore remaining warnings --- src/Serilog/Capturing/PropertyValueConverter.cs | 1 + src/Serilog/Context/LogContext.cs | 2 ++ src/Serilog/Core/Pipeline/MessageTemplateCache.cs | 2 ++ 3 files changed, 5 insertions(+) diff --git a/src/Serilog/Capturing/PropertyValueConverter.cs b/src/Serilog/Capturing/PropertyValueConverter.cs index d244271c9..3744b50e8 100644 --- a/src/Serilog/Capturing/PropertyValueConverter.cs +++ b/src/Serilog/Capturing/PropertyValueConverter.cs @@ -247,6 +247,7 @@ bool TryConvertValueTuple(object value, Destructuring destructuring, Type valueT definition == typeof(ValueTuple<,,,,>) || definition == typeof(ValueTuple<,,,,,>) || definition == typeof(ValueTuple<,,,,,,>)) #else + // ReSharper disable once PossibleNullReferenceException var defn = definition.FullName; if (defn == "System.ValueTuple`1" || defn == "System.ValueTuple`2" || defn == "System.ValueTuple`3" || defn == "System.ValueTuple`4" || diff --git a/src/Serilog/Context/LogContext.cs b/src/Serilog/Context/LogContext.cs index 7baaa9038..1be79e705 100644 --- a/src/Serilog/Context/LogContext.cs +++ b/src/Serilog/Context/LogContext.cs @@ -254,6 +254,8 @@ public DisposableObjectHandle(object o) : base(o) public override object InitializeLifetimeService() { var lease = (ILease)base.InitializeLifetimeService(); + // ReSharper disable once PossibleNullReferenceException + // not 100% sure this will never occur ... lease.Register(LifeTimeSponsor); return lease; } diff --git a/src/Serilog/Core/Pipeline/MessageTemplateCache.cs b/src/Serilog/Core/Pipeline/MessageTemplateCache.cs index 459a224a5..225ce0e73 100644 --- a/src/Serilog/Core/Pipeline/MessageTemplateCache.cs +++ b/src/Serilog/Core/Pipeline/MessageTemplateCache.cs @@ -51,6 +51,8 @@ public MessageTemplate Parse(string messageTemplate) return _innerParser.Parse(messageTemplate); #if HASHTABLE + // ReSharper disable once InconsistentlySynchronizedField + // ignored warning because this is by design var result = (MessageTemplate)_templates[messageTemplate]; if (result != null) return result;