From fe3d3e472ac2c83c1ae0e10b2a156fb4f16da940 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Wed, 7 Sep 2022 09:07:03 +1000 Subject: [PATCH] remove redundant type names (#1741) * remove redundant type names * Update KeyValuePairSettings.cs --- .../Capturing/PropertyValueConverter.cs | 2 +- .../Configuration/LoggerSinkConfiguration.cs | 2 +- src/Serilog/Core/Logger.cs | 2 +- .../Data/LogEventPropertyValueRewriter.cs | 2 +- src/Serilog/Parsing/MessageTemplateParser.cs | 4 ++-- .../Policies/SimpleScalarConversionPolicy.cs | 2 +- .../KeyValuePairs/KeyValuePairSettings.cs | 3 ++- .../MessageTemplateCacheBenchmark_Cached.cs | 2 +- .../Capturing/PropertyValueConverterTests.cs | 4 ++-- .../Core/SafeAggregateSinkTests.cs | 4 ++-- .../Formatting/Json/JsonFormatterTests.cs | 12 +++++----- .../Serilog.Tests/LoggerConfigurationTests.cs | 24 +++++++++---------- .../MethodOverloadConventionTests.cs | 4 ++-- 13 files changed, 34 insertions(+), 33 deletions(-) diff --git a/src/Serilog/Capturing/PropertyValueConverter.cs b/src/Serilog/Capturing/PropertyValueConverter.cs index d6c85b990..6c1a72a1f 100644 --- a/src/Serilog/Capturing/PropertyValueConverter.cs +++ b/src/Serilog/Capturing/PropertyValueConverter.cs @@ -392,7 +392,7 @@ IEnumerable GetProperties(object value) propValue = "Accessing this property is not supported via Reflection API"; } - yield return new LogEventProperty(prop.Name, _depthLimiter.CreatePropertyValue(propValue, Destructuring.Destructure)); + yield return new(prop.Name, _depthLimiter.CreatePropertyValue(propValue, Destructuring.Destructure)); } } diff --git a/src/Serilog/Configuration/LoggerSinkConfiguration.cs b/src/Serilog/Configuration/LoggerSinkConfiguration.cs index 40fc3a7cb..99bead87a 100644 --- a/src/Serilog/Configuration/LoggerSinkConfiguration.cs +++ b/src/Serilog/Configuration/LoggerSinkConfiguration.cs @@ -71,7 +71,7 @@ public LoggerConfiguration Sink( } else if (restrictedToMinimumLevel > LevelAlias.Minimum) { - sink = new RestrictedSink(sink, new LoggingLevelSwitch(restrictedToMinimumLevel)); + sink = new RestrictedSink(sink, new(restrictedToMinimumLevel)); } _addSink(sink); diff --git a/src/Serilog/Core/Logger.cs b/src/Serilog/Core/Logger.cs index 432a5575d..0162d107b 100644 --- a/src/Serilog/Core/Logger.cs +++ b/src/Serilog/Core/Logger.cs @@ -136,7 +136,7 @@ public ILogger ForContext(string propertyName, object? value, bool destructureOb // It'd be nice to do the destructuring lazily, but unfortunately `value` may be mutated between // now and the first log event written. var propertyValue = _messageTemplateProcessor.CreatePropertyValue(value, destructureObjects); - var enricher = new FixedPropertyEnricher(new EventProperty(propertyName, propertyValue)); + var enricher = new FixedPropertyEnricher(new(propertyName, propertyValue)); var minimumLevel = _minimumLevel; var levelSwitch = _levelSwitch; diff --git a/src/Serilog/Data/LogEventPropertyValueRewriter.cs b/src/Serilog/Data/LogEventPropertyValueRewriter.cs index 5bd13def4..07321fbbc 100644 --- a/src/Serilog/Data/LogEventPropertyValueRewriter.cs +++ b/src/Serilog/Data/LogEventPropertyValueRewriter.cs @@ -101,7 +101,7 @@ protected override LogEventPropertyValue VisitStructureValue(TState state, Struc for (var k = i; k < properties.Length; ++k) { var property = structure.Properties[k]; - properties[k] = new LogEventProperty(property.Name, Visit(state, property.Value)); + properties[k] = new(property.Name, Visit(state, property.Value)); } return new StructureValue(properties, structure.TypeTag); diff --git a/src/Serilog/Parsing/MessageTemplateParser.cs b/src/Serilog/Parsing/MessageTemplateParser.cs index cfb873448..ec2c4c8c7 100644 --- a/src/Serilog/Parsing/MessageTemplateParser.cs +++ b/src/Serilog/Parsing/MessageTemplateParser.cs @@ -33,7 +33,7 @@ public MessageTemplate Parse(string messageTemplate) { if (messageTemplate == null) throw new ArgumentNullException(nameof(messageTemplate)); - return new MessageTemplate(messageTemplate, Tokenize(messageTemplate)); + return new(messageTemplate, Tokenize(messageTemplate)); } static IEnumerable Tokenize(string messageTemplate) @@ -285,6 +285,6 @@ static TextToken ParseTextToken(int startAt, string messageTemplate, out int nex } while (startAt < messageTemplate.Length); next = startAt; - return new TextToken(accum.ToString(), first); + return new(accum.ToString(), first); } } diff --git a/src/Serilog/Policies/SimpleScalarConversionPolicy.cs b/src/Serilog/Policies/SimpleScalarConversionPolicy.cs index da2d197ef..6c030adc0 100644 --- a/src/Serilog/Policies/SimpleScalarConversionPolicy.cs +++ b/src/Serilog/Policies/SimpleScalarConversionPolicy.cs @@ -27,7 +27,7 @@ public bool TryConvertToScalar(object value, [NotNullWhen(true)] out ScalarValue { if (_scalarTypes.Contains(value.GetType())) { - result = new ScalarValue(value); + result = new(value); return true; } diff --git a/src/Serilog/Settings/KeyValuePairs/KeyValuePairSettings.cs b/src/Serilog/Settings/KeyValuePairs/KeyValuePairSettings.cs index 69ed99e18..4dfea7666 100644 --- a/src/Serilog/Settings/KeyValuePairs/KeyValuePairSettings.cs +++ b/src/Serilog/Settings/KeyValuePairs/KeyValuePairSettings.cs @@ -258,7 +258,8 @@ internal static IEnumerable LoadConfigurationAssemblies(IReadOnlyDicti if (string.IsNullOrWhiteSpace(usingDirective.Value)) throw new InvalidOperationException("A zero-length or whitespace assembly name was supplied to a serilog:using configuration statement."); - configurationAssemblies.Add(Assembly.Load(new AssemblyName(usingDirective.Value))); + var assemblyName = new AssemblyName(usingDirective.Value); + configurationAssemblies.Add(Assembly.Load(assemblyName)); } return configurationAssemblies.Distinct(); diff --git a/test/Serilog.PerformanceTests/MessageTemplateCacheBenchmark/MessageTemplateCacheBenchmark_Cached.cs b/test/Serilog.PerformanceTests/MessageTemplateCacheBenchmark/MessageTemplateCacheBenchmark_Cached.cs index dda8e6cd6..03690f564 100644 --- a/test/Serilog.PerformanceTests/MessageTemplateCacheBenchmark/MessageTemplateCacheBenchmark_Cached.cs +++ b/test/Serilog.PerformanceTests/MessageTemplateCacheBenchmark/MessageTemplateCacheBenchmark_Cached.cs @@ -60,7 +60,7 @@ void Run(Func cacheFactory) Parallel.For( 0, iterations, - new ParallelOptions { MaxDegreeOfParallelism = MaxDegreeOfParallelism }, + new() { MaxDegreeOfParallelism = MaxDegreeOfParallelism }, idx => cache.Parse(_templateList[idx % Items])); } } diff --git a/test/Serilog.Tests/Capturing/PropertyValueConverterTests.cs b/test/Serilog.Tests/Capturing/PropertyValueConverterTests.cs index 3c17c984c..ca740db36 100644 --- a/test/Serilog.Tests/Capturing/PropertyValueConverterTests.cs +++ b/test/Serilog.Tests/Capturing/PropertyValueConverterTests.cs @@ -114,7 +114,7 @@ class B [Fact] public void DestructuringACyclicStructureDoesNotStackOverflow() { - var ab = new A { B = new B() }; + var ab = new A { B = new() }; ab.B.A = ab; var pv = _converter.CreatePropertyValue(ab, true); @@ -136,7 +136,7 @@ class D [Fact] public void CollectionsAndCustomPoliciesInCyclesDoNotStackOverflow() { - var cd = new C { D = new D() }; + var cd = new C { D = new() }; cd.D.C = new List { cd }; var pv = _converter.CreatePropertyValue(cd, true); diff --git a/test/Serilog.Tests/Core/SafeAggregateSinkTests.cs b/test/Serilog.Tests/Core/SafeAggregateSinkTests.cs index 70b9fac4d..e04d8b4e1 100644 --- a/test/Serilog.Tests/Core/SafeAggregateSinkTests.cs +++ b/test/Serilog.Tests/Core/SafeAggregateSinkTests.cs @@ -9,7 +9,7 @@ public void AnExceptionThrownByASinkIsNotPropagated() var s = new SafeAggregateSink(new[] { new DelegatingSink(_ => { thrown = true; - throw new Exception("No go, pal."); + throw new("No go, pal."); }) }); s.Emit(Some.InformationEvent()); @@ -24,7 +24,7 @@ public void WhenASinkThrowsOtherSinksAreStillInvoked() var s = new SafeAggregateSink(new[] { new DelegatingSink(_ => called1 = true), - new DelegatingSink(_ => throw new Exception("No go, pal.")), + new DelegatingSink(_ => throw new("No go, pal.")), new DelegatingSink(_ => called2 = true) }); diff --git a/test/Serilog.Tests/Formatting/Json/JsonFormatterTests.cs b/test/Serilog.Tests/Formatting/Json/JsonFormatterTests.cs index d5a53799a..f4f287591 100644 --- a/test/Serilog.Tests/Formatting/Json/JsonFormatterTests.cs +++ b/test/Serilog.Tests/Formatting/Json/JsonFormatterTests.cs @@ -8,7 +8,7 @@ public class JsonFormatterTests public void JsonFormattedEventsIncludeTimestamp() { var @event = new LogEvent( - new DateTimeOffset(2013, 3, 11, 15, 59, 0, 123, TimeSpan.FromHours(10)), + new(2013, 3, 11, 15, 59, 0, 123, TimeSpan.FromHours(10)), Information, null, Some.MessageTemplate(), @@ -78,7 +78,7 @@ public void AnIntegerPropertySerializesAsIntegerValue() var name = Some.String(); var value = Some.Int(); var @event = Some.InformationEvent(); - @event.AddOrUpdateProperty(new LogEventProperty(name, new ScalarValue(value))); + @event.AddOrUpdateProperty(new(name, new ScalarValue(value))); var formatted = FormatJson(@event); @@ -91,7 +91,7 @@ public void ABooleanPropertySerializesAsBooleanValue() var name = Some.String(); const bool value = true; var @event = Some.InformationEvent(); - @event.AddOrUpdateProperty(new LogEventProperty(name, new ScalarValue(value))); + @event.AddOrUpdateProperty(new(name, new ScalarValue(value))); var formatted = FormatJson(@event); @@ -104,7 +104,7 @@ public void ACharPropertySerializesAsStringValue() var name = Some.String(); const char value = 'c'; var @event = Some.InformationEvent(); - @event.AddOrUpdateProperty(new LogEventProperty(name, new ScalarValue(value))); + @event.AddOrUpdateProperty(new(name, new ScalarValue(value))); var formatted = FormatJson(@event); @@ -117,7 +117,7 @@ public void ADecimalSerializesAsNumericValue() var name = Some.String(); const decimal value = 123.45m; var @event = Some.InformationEvent(); - @event.AddOrUpdateProperty(new LogEventProperty(name, new ScalarValue(value))); + @event.AddOrUpdateProperty(new(name, new ScalarValue(value))); var formatted = FormatJson(@event); @@ -131,7 +131,7 @@ public void ASequencePropertySerializesAsArrayValue() var ints = new[]{ Some.Int(), Some.Int() }; var value = new SequenceValue(ints.Select(i => new ScalarValue(i))); var @event = Some.InformationEvent(); - @event.AddOrUpdateProperty(new LogEventProperty(name, value)); + @event.AddOrUpdateProperty(new(name, value)); var formatted = FormatJson(@event); var result = new List(); diff --git a/test/Serilog.Tests/LoggerConfigurationTests.cs b/test/Serilog.Tests/LoggerConfigurationTests.cs index d3710b5d9..554dd394d 100644 --- a/test/Serilog.Tests/LoggerConfigurationTests.cs +++ b/test/Serilog.Tests/LoggerConfigurationTests.cs @@ -31,7 +31,7 @@ public void LoggerShouldNotReferenceToItsConfigurationAfterBeingCreated() static (ILogger, WeakReference) CreateLogger() { var loggerConfiguration = new LoggerConfiguration(); - return (loggerConfiguration.CreateLogger(), new WeakReference(loggerConfiguration)); + return (loggerConfiguration.CreateLogger(), new(loggerConfiguration)); } } @@ -490,7 +490,7 @@ public void LevelSwitchTakesPrecedenceOverMinimumLevel() var sink = new CollectingSink(); var logger = new LoggerConfiguration() - .WriteTo.Sink(sink, Fatal, new LoggingLevelSwitch()) + .WriteTo.Sink(sink, Fatal, new()) .CreateLogger(); logger.Write(Some.InformationEvent()); @@ -504,7 +504,7 @@ public void LastMinimumLevelConfigurationWins() var sink = new CollectingSink(); var logger = new LoggerConfiguration() - .MinimumLevel.ControlledBy(new LoggingLevelSwitch(Fatal)) + .MinimumLevel.ControlledBy(new(Fatal)) .MinimumLevel.Debug() .WriteTo.Sink(sink) .CreateLogger(); @@ -554,7 +554,7 @@ public void LowerMinimumLevelOverridesArePropagated() public void ExceptionsThrownBySinksAreNotPropagated() { var logger = new LoggerConfiguration() - .WriteTo.Sink(new DelegatingSink(_ => throw new Exception("Boom!"))) + .WriteTo.Sink(new DelegatingSink(_ => throw new("Boom!"))) .CreateLogger(); logger.Write(Some.InformationEvent()); @@ -567,7 +567,7 @@ public void ExceptionsThrownBySinksAreNotPropagatedEvenWhenAuditingIsPresent() { var logger = new LoggerConfiguration() .AuditTo.Sink(new CollectingSink()) - .WriteTo.Sink(new DelegatingSink(_ => throw new Exception("Boom!"))) + .WriteTo.Sink(new DelegatingSink(_ => throw new("Boom!"))) .CreateLogger(); logger.Write(Some.InformationEvent()); @@ -579,7 +579,7 @@ public void ExceptionsThrownBySinksAreNotPropagatedEvenWhenAuditingIsPresent() public void ExceptionsThrownByFiltersAreNotPropagated() { var logger = new LoggerConfiguration() - .Filter.ByExcluding(_ => throw new Exception("Boom!")) + .Filter.ByExcluding(_ => throw new("Boom!")) .CreateLogger(); logger.Write(Some.InformationEvent()); @@ -594,7 +594,7 @@ public void ExceptionsThrownByDestructuringPoliciesAreNotPropagated() { var logger = new LoggerConfiguration() .WriteTo.Sink(new CollectingSink()) - .Destructure.ByTransforming(_ => throw new Exception("Boom!")) + .Destructure.ByTransforming(_ => throw new("Boom!")) .CreateLogger(); logger.Information("{@Value}", new Value()); @@ -605,7 +605,7 @@ public void ExceptionsThrownByDestructuringPoliciesAreNotPropagated() class ThrowingProperty { // ReSharper disable once UnusedMember.Local - public string Property => throw new Exception("Boom!"); + public string Property => throw new("Boom!"); } [Fact] @@ -704,8 +704,8 @@ public void WrappingSinkRespectsLevelSwitchSetting() var sink = new CollectingSink(); var logger = new LoggerConfiguration() .WriteTo.DummyWrap( - w => w.Sink(sink), Verbose, - new LoggingLevelSwitch(Error)) + w => w.Sink(sink), LogEventLevel.Verbose, + new(Error)) .CreateLogger(); logger.Write(Some.InformationEvent()); @@ -721,8 +721,8 @@ public void WrappingSinkReceivesEventsWhenLevelIsAppropriate() var sink = new CollectingSink(); var logger = new LoggerConfiguration() .WriteTo.DummyWrap( - w => w.Sink(sink), Error, - new LoggingLevelSwitch(Verbose)) + w => w.Sink(sink), LogEventLevel.Error, + new(Verbose)) .CreateLogger(); logger.Write(Some.InformationEvent()); diff --git a/test/Serilog.Tests/MethodOverloadConventionTests.cs b/test/Serilog.Tests/MethodOverloadConventionTests.cs index 38fa6132c..a053e01b3 100644 --- a/test/Serilog.Tests/MethodOverloadConventionTests.cs +++ b/test/Serilog.Tests/MethodOverloadConventionTests.cs @@ -1019,7 +1019,7 @@ static void EvaluateSingleResult(LogEventLevel level, CollectingSink? results) if (loggerType == typeof(Logger) || loggerType == typeof(ILogger)) { - sink = new CollectingSink(); + sink = new(); return new LoggerConfiguration() .MinimumLevel.Is(level) @@ -1029,7 +1029,7 @@ static void EvaluateSingleResult(LogEventLevel level, CollectingSink? results) if (loggerType == typeof(Log)) { - sink = new CollectingSink(); + sink = new(); Log.CloseAndFlush();