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

minor cleanups #1746

Merged
merged 1 commit into from Sep 5, 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/ILogger.cs
Expand Up @@ -65,7 +65,7 @@ ILogger ForContext(IEnumerable<ILogEventEnricher> enrichers)
if (enrichers == null)
return this; // No context here, so little point writing to SelfLog.

return ForContext(new Core.Enrichers.SafeAggregateEnricher(enrichers));
return ForContext(new SafeAggregateEnricher(enrichers));
}
#else
;
Expand Down
17 changes: 8 additions & 9 deletions test/Serilog.Tests/Capturing/PropertyValueConverterTests.cs
Expand Up @@ -164,7 +164,7 @@ public void ByDefaultANonScalarDictionaryIsASequenceValue()
[Fact]
public void DelegatesAreConvertedToScalarStringsWhenDestructuring()
{
Action del = DelegatesAreConvertedToScalarStringsWhenDestructuring;
var del = DelegatesAreConvertedToScalarStringsWhenDestructuring;
var pv = _converter.CreatePropertyValue(del, Destructuring.Destructure);
Assert.IsType<ScalarValue>(pv);
Assert.IsType<string>(pv.LiteralValue());
Expand Down Expand Up @@ -236,7 +236,6 @@ public void FailsGracefullyWhenAccessingPropertiesViaReflectionThrows()
Assert.Equal(3, l.Value.LiteralValue());
var k = sv.Properties.Single(m => m.Name == "IsEmpty");
Assert.False((bool?)k.Value.LiteralValue());
var s = sv.Properties.Single(m => m.Name == "Span");
}
#endif

Expand Down Expand Up @@ -266,13 +265,13 @@ public void SurvivesDestructuringASystemType()
}

#if GETCURRENTMETHOD
[Fact]
public void SurvivesDestructuringMethodBase()
{
var theMethod = System.Reflection.MethodBase.GetCurrentMethod();
var pv = _converter.CreatePropertyValue(theMethod, Destructuring.Destructure);
Assert.Equal(theMethod, pv.LiteralValue());
}
[Fact]
public void SurvivesDestructuringMethodBase()
{
var theMethod = MethodBase.GetCurrentMethod();
var pv = _converter.CreatePropertyValue(theMethod, Destructuring.Destructure);
Assert.Equal(theMethod, pv.LiteralValue());
}
#endif

public class BaseWithProps
Expand Down
Expand Up @@ -9,8 +9,7 @@ public LogEventPropertyValue LimitStringLength(LogEventPropertyValue value, int

protected override LogEventPropertyValue VisitScalarValue(int state, ScalarValue scalar)
{
var str = scalar.Value as string;
if (str == null || str.Length <= state)
if (scalar.Value is not string str || str.Length <= state)
return scalar;

return new ScalarValue(str.Substring(0, state));
Expand Down
2 changes: 0 additions & 2 deletions test/Serilog.Tests/Debugging/SelfLogTests.cs
Expand Up @@ -11,7 +11,6 @@ public void MessagesAreWrittenWhenOutputIsSet()
Messages = new();
SelfLog.Enable(m =>
{
Messages ??= new();
Messages.Add(m);
});

Expand All @@ -32,7 +31,6 @@ public void WritingToUndeclaredSinkWritesToSelfLog()
Messages = new();
SelfLog.Enable(m =>
{
Messages ??= new();
Messages.Add(m);
});

Expand Down
2 changes: 1 addition & 1 deletion test/Serilog.Tests/Filters/MatchingTests.cs
Expand Up @@ -58,7 +58,7 @@ public void SourceFiltersSkipNonNamespaces()
.Filter.ByExcluding(Matching.FromSource("Serilog.Tests"))
.WriteTo.Sink(new DelegatingSink(_ => written = true))
.CreateLogger()
.ForContext(Serilog.Core.Constants.SourceContextPropertyName, "Serilog.TestsLong");
.ForContext(Constants.SourceContextPropertyName, "Serilog.TestsLong");

log.Write(Some.InformationEvent());
Assert.True(written);
Expand Down
4 changes: 2 additions & 2 deletions test/Serilog.Tests/MethodOverloadConventionTests.cs
Expand Up @@ -958,12 +958,12 @@ static void VerifyMethodSignature(MethodInfo method, bool hasExceptionArg = fals

//check for params argument: params object[] propertyValues
//params argument currently has to be the last argument, and generic methods don't have params argument
if (!isGeneric && (parameters.Length - index) == 1)
if (!isGeneric && parameters.Length - index == 1)
{
var paramsArrayArg = parameters[index];

// params array attribute should never have derived/inherited classes
var paramsAttr = parameters[index].GetCustomAttribute(typeof(ParamArrayAttribute), inherit: false);
var paramsAttr = paramsArrayArg.GetCustomAttribute(typeof(ParamArrayAttribute), inherit: false);

Assert.NotNull(paramsAttr);
Assert.Equal(typeof(object[]), paramsArrayArg.ParameterType);
Expand Down