Skip to content

Commit c165ac5

Browse files
committed
pattern matching
1 parent 126a0bf commit c165ac5

File tree

3 files changed

+6
-7
lines changed

3 files changed

+6
-7
lines changed

src/Serilog.Extensions.Logging/Extensions/Logging/LoggerProviderCollectionSink.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ public void Emit(LogEvent logEvent)
3333
EventId eventId = default;
3434

3535
if (logEvent.Properties.TryGetValue("SourceContext", out var sourceContextProperty) &&
36-
sourceContextProperty is ScalarValue sourceContextValue &&
37-
sourceContextValue.Value is string sourceContext)
36+
sourceContextProperty is ScalarValue {Value: string sourceContext})
3837
{
3938
categoryName = sourceContext;
4039
}
@@ -44,8 +43,8 @@ sourceContextProperty is ScalarValue sourceContextValue &&
4443
var id = 0;
4544
foreach (var item in structuredEventId.Properties)
4645
{
47-
if (item.Name == "Id" && item.Value is ScalarValue sv && sv.Value is int i) id = i;
48-
if (item.Name == "Name" && item.Value is ScalarValue sv2 && sv2.Value is string s) name = s;
46+
if (item.Name == "Id" && item.Value is ScalarValue {Value: int i}) id = i;
47+
if (item is {Name: "Name", Value: ScalarValue {Value: string s}}) name = s;
4948
}
5049

5150
eventId = new EventId(id, name);

src/Serilog.Extensions.Logging/Extensions/Logging/SerilogLogger.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ void Write<TState>(LogEventLevel level, EventId eventId, TState state, Exception
9595
{
9696
foreach (var property in structure)
9797
{
98-
if (property.Key == SerilogLoggerProvider.OriginalFormatPropertyName && property.Value is string value)
98+
if (property is {Key: SerilogLoggerProvider.OriginalFormatPropertyName, Value: string value})
9999
{
100100
messageTemplate = value;
101101
}

src/Serilog.Extensions.Logging/Extensions/Logging/SerilogLoggerScope.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ void AddProperty(KeyValuePair<string, object> stateProperty)
8585

8686
foreach (var stateProperty in dictionary)
8787
{
88-
if (stateProperty.Key == SerilogLoggerProvider.OriginalFormatPropertyName && stateProperty.Value is string)
88+
if (stateProperty is {Key: SerilogLoggerProvider.OriginalFormatPropertyName, Value: string})
8989
scopeItem = new ScalarValue(_state.ToString());
9090
else
9191
AddProperty(stateProperty);
@@ -97,7 +97,7 @@ void AddProperty(KeyValuePair<string, object> stateProperty)
9797

9898
foreach (var stateProperty in stateProperties)
9999
{
100-
if (stateProperty.Key == SerilogLoggerProvider.OriginalFormatPropertyName && stateProperty.Value is string)
100+
if (stateProperty is {Key: SerilogLoggerProvider.OriginalFormatPropertyName, Value: string})
101101
scopeItem = new ScalarValue(_state.ToString());
102102
else
103103
AddProperty(stateProperty);

0 commit comments

Comments
 (0)