@@ -496,34 +496,37 @@ private static int FindMaxIndex(MessageTemplateParameters messageTemplateParamet
496496 private void CaptureEventIdProperties ( LogEventInfo logEvent , in EventId eventId )
497497 {
498498 var captureEventId = _options . CaptureEventId ;
499- if ( captureEventId != EventIdCaptureType . None && IncludeEventIdProperties ( eventId ) )
500- {
501- if ( ( captureEventId & EventIdCaptureType . EventId ) != 0 )
502- logEvent . Properties [ nameof ( EventIdCaptureType . EventId ) ] = GetEventId ( eventId . Id ) ;
499+ if ( captureEventId == EventIdCaptureType . None )
500+ return ;
503501
504- if ( ( captureEventId & EventIdCaptureType . EventName ) != 0 && eventId . Name != null )
505- logEvent . Properties [ nameof ( EventIdCaptureType . EventName ) ] = eventId . Name ;
502+ if ( ! IncludeEventIdProperties ( eventId ) )
503+ return ;
504+
505+ if ( ( captureEventId & EventIdCaptureType . EventId ) != 0 )
506+ logEvent . Properties [ nameof ( EventIdCaptureType . EventId ) ] = GetEventId ( eventId . Id ) ;
506507
507- if ( ( captureEventId & EventIdCaptureType . Legacy ) != 0 )
508+ if ( ( captureEventId & EventIdCaptureType . EventName ) != 0 && eventId . Name is not null )
509+ logEvent . Properties [ nameof ( EventIdCaptureType . EventName ) ] = eventId . Name ;
510+
511+ if ( ( captureEventId & EventIdCaptureType . Legacy ) != 0 )
512+ {
513+ // Attempt to reuse the same string-allocations based on the current <see cref="NLogProviderOptions.EventIdSeparator"/>
514+ var eventIdPropertyNames = _eventIdPropertyNames ;
515+ var eventIdSeparator = _options . EventIdSeparator ?? String . Empty ;
516+ if ( ! ReferenceEquals ( eventIdPropertyNames ? . Item1 , eventIdSeparator ) )
508517 {
509- // Attempt to reuse the same string-allocations based on the current <see cref="NLogProviderOptions.EventIdSeparator"/>
510- var eventIdPropertyNames = _eventIdPropertyNames ;
511- var eventIdSeparator = _options . EventIdSeparator ?? String . Empty ;
512- if ( ! ReferenceEquals ( eventIdPropertyNames ? . Item1 , eventIdSeparator ) )
513- {
514- // Perform atomic cache update of the string-allocations matching the current separator
515- _eventIdPropertyNames = eventIdPropertyNames = CreateEventIdPropertyNames ( eventIdSeparator ) ;
516- }
518+ // Perform atomic cache update of the string-allocations matching the current separator
519+ _eventIdPropertyNames = eventIdPropertyNames = CreateEventIdPropertyNames ( eventIdSeparator ) ;
520+ }
517521
518- if ( ( captureEventId & EventIdCaptureType . EventId_Id ) != 0 )
519- logEvent . Properties [ eventIdPropertyNames . Item2 ] = GetEventId ( eventId . Id ) ;
522+ if ( ( captureEventId & EventIdCaptureType . EventId_Id ) != 0 )
523+ logEvent . Properties [ eventIdPropertyNames . Item2 ] = GetEventId ( eventId . Id ) ;
520524
521- if ( ( captureEventId & EventIdCaptureType . EventId_Name ) != 0 && eventId . Name != null )
522- logEvent . Properties [ eventIdPropertyNames . Item3 ] = eventId . Name ;
525+ if ( ( captureEventId & EventIdCaptureType . EventId_Name ) != 0 && eventId . Name is not null )
526+ logEvent . Properties [ eventIdPropertyNames . Item3 ] = eventId . Name ;
523527
524- if ( ( captureEventId & EventIdCaptureType . EventIdStruct ) != 0 )
525- logEvent . Properties [ nameof ( EventIdCaptureType . EventId ) ] = eventId ;
526- }
528+ if ( ( captureEventId & EventIdCaptureType . EventIdStruct ) != 0 )
529+ logEvent . Properties [ nameof ( EventIdCaptureType . EventId ) ] = eventId ;
527530 }
528531 }
529532
0 commit comments