@@ -296,7 +296,8 @@ private static void SetLogEventMessageFormatter(LogEventInfo logEvent, NLogMessa
296296
297297 private void CaptureEventIdProperties ( LogEventInfo logEvent , EventId eventId )
298298 {
299- if ( IncludeEventIdProperties ( eventId ) )
299+ var captureEventId = _options . CaptureEventId ;
300+ if ( captureEventId != EventIdCaptureType . None && IncludeEventIdProperties ( eventId ) )
300301 {
301302 // Attempt to reuse the same string-allocations based on the current <see cref="NLogProviderOptions.EventIdSeparator"/>
302303 var eventIdPropertyNames = _eventIdPropertyNames ?? new Tuple < string , string , string > ( null , null , null ) ;
@@ -307,20 +308,20 @@ private void CaptureEventIdProperties(LogEventInfo logEvent, EventId eventId)
307308 _eventIdPropertyNames = eventIdPropertyNames = CreateEventIdPropertyNames ( eventIdSeparator ) ;
308309 }
309310
310- if ( ( _options . CaptureEventId & EventIdCaptureType . EventId_Name ) != 0 && eventId . Name != null )
311- logEvent . Properties [ eventIdPropertyNames . Item3 ] = eventId . Name ;
312-
313- if ( ( _options . CaptureEventId & EventIdCaptureType . EventId_Id ) != 0 && ( eventId . Id != 0 || eventId . Name != null ) )
311+ if ( ( captureEventId & EventIdCaptureType . EventId_Id ) != 0 )
314312 logEvent . Properties [ eventIdPropertyNames . Item2 ] = eventId . Id == 0 ? ZeroEventId : GetEventId ( eventId . Id ) ;
315313
316- if ( ( _options . CaptureEventId & EventIdCaptureType . EventId ) != 0 )
314+ if ( ( captureEventId & EventIdCaptureType . EventId_Name ) != 0 && eventId . Name != null )
315+ logEvent . Properties [ eventIdPropertyNames . Item3 ] = eventId . Name ;
316+
317+ if ( ( captureEventId & EventIdCaptureType . EventId ) != 0 )
317318 logEvent . Properties [ nameof ( EventId ) ] = eventId ;
318319 }
319320 }
320321
321322 private bool IncludeEventIdProperties ( EventId eventId )
322323 {
323- return ( eventId . Id != 0 || ! string . IsNullOrEmpty ( eventId . Name ) || ! _options . IgnoreEmptyEventId ) && _options . CaptureEventId != EventIdCaptureType . None ;
324+ return ( eventId . Id != 0 || ! string . IsNullOrEmpty ( eventId . Name ) || ! _options . IgnoreEmptyEventId ) ;
324325 }
325326
326327 private static Tuple < string , string , string > CreateEventIdPropertyNames ( string eventIdSeparator )
0 commit comments