Skip to content

Commit

Permalink
use some patterns (#1739)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp committed Sep 1, 2022
1 parent c5a5b44 commit 70e729d
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/Serilog/Configuration/LoggerEnrichmentConfiguration.cs
Expand Up @@ -178,7 +178,7 @@ public LoggerConfiguration AtLevel(LoggingLevelSwitch levelSwitch, Action<Logger
var wrappedEnricher = wrapEnricher(enclosed);

// ReSharper disable once SuspiciousTypeConversion.Global
if (!(wrappedEnricher is IDisposable))
if (wrappedEnricher is not IDisposable)
{
SelfLog.WriteLine("Wrapping enricher {0} does not implement IDisposable; to ensure " +
"wrapped enrichers are properly disposed, wrappers should dispose " +
Expand Down
4 changes: 2 additions & 2 deletions src/Serilog/Configuration/LoggerSinkConfiguration.cs
Expand Up @@ -147,7 +147,7 @@ internal LoggerSinkConfiguration(LoggerConfiguration loggerConfiguration, Action
{
if (logger == null) throw new ArgumentNullException(nameof(logger));

if (logger is Logger concreteLogger && concreteLogger.HasOverrideMap)
if (logger is Logger {HasOverrideMap: true})
{
SelfLog.WriteLine("Minimum level overrides are not supported on sub-loggers " +
"and may be removed completely in a future version.");
Expand Down Expand Up @@ -240,7 +240,7 @@ public LoggerConfiguration Conditional(Func<LogEvent, bool> condition, Action<Lo
new DisposingAggregateSink(sinksToWrap);

var wrappedSink = wrapSink(enclosed);
if (!(wrappedSink is IDisposable) && enclosed is IDisposable target)
if (wrappedSink is not IDisposable && enclosed is IDisposable target)
{
wrappedSink = new DisposeDelegatingSink(wrappedSink, target);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Serilog/Core/Sinks/DisposingAggregateSink.cs
Expand Up @@ -49,7 +49,7 @@ public void Dispose()
{
foreach (var sink in _sinks)
{
if (!(sink is IDisposable disposable)) continue;
if (sink is not IDisposable disposable) continue;

try
{
Expand Down
5 changes: 2 additions & 3 deletions src/Serilog/Filters/Matching.cs
Expand Up @@ -98,9 +98,8 @@ public static class Matching
{
if (!e.Properties.TryGetValue(propertyName, out var propertyValue)) return false;
return propertyValue is ScalarValue s &&
((s.Value is TScalar value) &&
predicate(value));
return propertyValue is ScalarValue {Value: TScalar value} &&
predicate(value);
};
}
}
2 changes: 1 addition & 1 deletion test/TestDummies/DummyAnonymousUserFilter.cs
Expand Up @@ -8,7 +8,7 @@ public bool IsEnabled(LogEvent logEvent)
{
if (logEvent.Properties["User"] is ScalarValue sv)
{
if (sv.Value is string s && s == "anonymous")
if (sv.Value is "anonymous")
{
return false;
}
Expand Down

0 comments on commit 70e729d

Please sign in to comment.