@@ -106,7 +106,7 @@ private void WriteEvent(LogEvent logEvent, XmlWriter writer)
106
106
WriteEventAttribute ( logEvent , writer , "thread" , ThreadIdPropertyName ) ;
107
107
WriteDomainAndUserName ( logEvent , writer ) ;
108
108
var properties = logEvent . Properties . Where ( e => ! SpecialProperties . Contains ( e . Key ) ) . ToList ( ) ;
109
- var hasMachineNameProperty = logEvent . Properties . TryGetValue ( MachineNamePropertyName , out var machineNameProperty ) && machineNameProperty is ScalarValue scalarValue && scalarValue . Value != null ;
109
+ var hasMachineNameProperty = logEvent . Properties . TryGetValue ( MachineNamePropertyName , out var machineNameProperty ) && machineNameProperty is ScalarValue { Value : not null } ;
110
110
if ( properties . Any ( ) || hasMachineNameProperty )
111
111
{
112
112
WriteProperties ( logEvent , writer , properties , machineNameProperty ) ;
@@ -123,7 +123,7 @@ private void WriteEvent(LogEvent logEvent, XmlWriter writer)
123
123
/// <param name="writer">The XML writer.</param>
124
124
private static void WriteDomainAndUserName ( LogEvent logEvent , XmlWriter writer )
125
125
{
126
- if ( logEvent . Properties . TryGetValue ( UserNamePropertyName , out var propertyValue ) && propertyValue is ScalarValue scalarValue && scalarValue . Value is string userNameProperty )
126
+ if ( logEvent . Properties . TryGetValue ( UserNamePropertyName , out var propertyValue ) && propertyValue is ScalarValue { Value : string userNameProperty } )
127
127
{
128
128
// See https://github.com/serilog/serilog-enrichers-environment/blob/3fc7cf78c5f34816633000ae74d846033498e44b/src/Serilog.Enrichers.Environment/Enrichers/EnvironmentUserNameEnricher.cs#L53
129
129
var parts = userNameProperty . Split ( '\\ ' ) ;
@@ -149,9 +149,9 @@ private static void WriteDomainAndUserName(LogEvent logEvent, XmlWriter writer)
149
149
/// <remarks>Only properties with a non null <see cref="ScalarValue"/> are supported, other types are ignored.</remarks>
150
150
private void WriteEventAttribute ( LogEvent logEvent , XmlWriter writer , string attributeName , string propertyName )
151
151
{
152
- if ( logEvent . Properties . TryGetValue ( propertyName , out var propertyValue ) && propertyValue is ScalarValue scalarValue && scalarValue . Value != null )
152
+ if ( logEvent . Properties . TryGetValue ( propertyName , out var propertyValue ) && propertyValue is ScalarValue { Value : not null } )
153
153
{
154
- writer . WriteAttributeString ( attributeName , RenderValue ( scalarValue ) ) ;
154
+ writer . WriteAttributeString ( attributeName , RenderValue ( propertyValue ) ) ;
155
155
}
156
156
}
157
157
@@ -225,7 +225,7 @@ private string RenderValue(LogEventPropertyValue value)
225
225
{
226
226
using var valueWriter = new StringWriter ( ) ;
227
227
// The "l" format specifier switches off quoting of strings, see https://github.com/serilog/serilog/wiki/Formatting-Output#formatting-plain-text
228
- value . Render ( valueWriter , value is ScalarValue scalarValue && scalarValue . Value is string ? "l" : null , _options . FormatProvider ) ;
228
+ value . Render ( valueWriter , value is ScalarValue { Value : string } ? "l" : null , _options . FormatProvider ) ;
229
229
return valueWriter . ToString ( ) ;
230
230
}
231
231
@@ -321,7 +321,7 @@ private void WritePropertyElement(XmlWriter writer, string name, LogEventPropert
321
321
{
322
322
WriteStartElement ( writer , "data" ) ;
323
323
writer . WriteAttributeString ( "name" , name ) ;
324
- var isNullValue = value is ScalarValue scalarValue && scalarValue . Value == null ;
324
+ var isNullValue = value is ScalarValue { Value : null } ;
325
325
if ( ! isNullValue )
326
326
{
327
327
writer . WriteAttributeString ( "value" , RenderValue ( value ) ) ;
0 commit comments