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

remove redundant type names #1741

Merged
merged 3 commits into from Sep 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Serilog/Capturing/PropertyValueConverter.cs
Expand Up @@ -392,7 +392,7 @@ IEnumerable<LogEventProperty> 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));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Serilog/Configuration/LoggerSinkConfiguration.cs
Expand Up @@ -71,7 +71,7 @@ internal LoggerSinkConfiguration(LoggerConfiguration loggerConfiguration, Action
}
else if (restrictedToMinimumLevel > LevelAlias.Minimum)
{
sink = new RestrictedSink(sink, new LoggingLevelSwitch(restrictedToMinimumLevel));
sink = new RestrictedSink(sink, new(restrictedToMinimumLevel));
}

_addSink(sink);
Expand Down
2 changes: 1 addition & 1 deletion src/Serilog/Core/Logger.cs
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Serilog/Data/LogEventPropertyValueRewriter.cs
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/Serilog/Parsing/MessageTemplateParser.cs
Expand Up @@ -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<MessageTemplateToken> Tokenize(string messageTemplate)
Expand Down Expand Up @@ -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);
}
}
2 changes: 1 addition & 1 deletion src/Serilog/Policies/SimpleScalarConversionPolicy.cs
Expand Up @@ -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;
}

Expand Down
3 changes: 2 additions & 1 deletion src/Serilog/Settings/KeyValuePairs/KeyValuePairSettings.cs
Expand Up @@ -258,7 +258,8 @@ internal static IEnumerable<Assembly> 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();
Expand Down
Expand Up @@ -60,7 +60,7 @@ void Run<T>(Func<T> cacheFactory)
Parallel.For(
0,
iterations,
new ParallelOptions { MaxDegreeOfParallelism = MaxDegreeOfParallelism },
new() { MaxDegreeOfParallelism = MaxDegreeOfParallelism },
idx => cache.Parse(_templateList[idx % Items]));
}
}
4 changes: 2 additions & 2 deletions test/Serilog.Tests/Capturing/PropertyValueConverterTests.cs
Expand Up @@ -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);
Expand All @@ -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<C?> { cd };

var pv = _converter.CreatePropertyValue(cd, true);
Expand Down
4 changes: 2 additions & 2 deletions test/Serilog.Tests/Core/SafeAggregateSinkTests.cs
Expand Up @@ -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());
Expand All @@ -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)
});

Expand Down
12 changes: 6 additions & 6 deletions test/Serilog.Tests/Formatting/Json/JsonFormatterTests.cs
Expand Up @@ -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(),
Expand Down Expand Up @@ -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);

Expand All @@ -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);

Expand All @@ -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);

Expand All @@ -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);

Expand All @@ -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<int>();
Expand Down
24 changes: 12 additions & 12 deletions test/Serilog.Tests/LoggerConfigurationTests.cs
Expand Up @@ -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));
}
}

Expand Down Expand Up @@ -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());
Expand All @@ -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();
Expand Down Expand Up @@ -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());
Expand All @@ -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());
Expand All @@ -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());
Expand All @@ -594,7 +594,7 @@ public void ExceptionsThrownByDestructuringPoliciesAreNotPropagated()
{
var logger = new LoggerConfiguration()
.WriteTo.Sink(new CollectingSink())
.Destructure.ByTransforming<Value>(_ => throw new Exception("Boom!"))
.Destructure.ByTransforming<Value>(_ => throw new("Boom!"))
.CreateLogger();

logger.Information("{@Value}", new Value());
Expand All @@ -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]
Expand Down Expand Up @@ -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());
Expand All @@ -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());
Expand Down
4 changes: 2 additions & 2 deletions test/Serilog.Tests/MethodOverloadConventionTests.cs
Expand Up @@ -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)
Expand All @@ -1029,7 +1029,7 @@ static void EvaluateSingleResult(LogEventLevel level, CollectingSink? results)

if (loggerType == typeof(Log))
{
sink = new CollectingSink();
sink = new();

Log.CloseAndFlush();

Expand Down