FileTarget - Reduce code complexity for ArchiveNumbering property#6064
FileTarget - Reduce code complexity for ArchiveNumbering property#6064
Conversation
WalkthroughThe Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~5 minutes
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 inconclusive)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: Repository UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/NLog/Targets/FileTarget.cs (1)
393-402: LGTM! Refactoring successfully reduces complexity.The changes effectively simplify the setter by trimming once, providing early exit for unchanged values, and consistently using the local
archiveNumberingvariable. The logic is correct and the control flow ensures line 400 is safe from null reference exceptions.Minor: The null check on line 394 is redundant since
string.IsNullOrEmptyalready handles null cases. Consider simplifying:-if (archiveNumbering is null || string.IsNullOrEmpty(archiveNumbering) || string.Equals(_archiveNumbering, archiveNumbering, StringComparison.OrdinalIgnoreCase)) +if (string.IsNullOrEmpty(archiveNumbering) || string.Equals(_archiveNumbering, archiveNumbering, StringComparison.OrdinalIgnoreCase))
📜 Review details
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/NLog/Targets/FileTarget.cs(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/NLog/Targets/FileTarget.cs (2)
src/NLog/Internal/PropertiesDictionary.cs (4)
Equals(748-748)Equals(750-758)Equals(772-775)Equals(786-800)src/NLog/Filters/WhenRepeatedFilter.cs (2)
Equals(391-407)Equals(409-412)
1032d00 to
02b891f
Compare
|
| _archiveNumbering = string.IsNullOrEmpty(value) ? null : value.Trim(); | ||
| if (_archiveNumbering is null || string.IsNullOrEmpty(_archiveNumbering)) | ||
| var archiveNumbering = value?.Trim() ?? string.Empty; | ||
| if (string.IsNullOrEmpty(archiveNumbering) || string.Equals(_archiveNumbering, archiveNumbering, StringComparison.OrdinalIgnoreCase)) |
There was a problem hiding this comment.
| if (string.IsNullOrEmpty(archiveNumbering) || string.Equals(_archiveNumbering, archiveNumbering, StringComparison.OrdinalIgnoreCase)) | |
| if (string.IsNullOrEmpty(archiveNumbering) || archiveNumbering.Equals(_archiveNumbering, StringComparison.OrdinalIgnoreCase)) |
this will reduce one null check that is called in the static string.Equals method
There was a problem hiding this comment.
Old habit of using string.Equals not that worried about a bonus null-check for an obsolete property. But thank you for noticing.
| if (_archiveSuffixFormat is null || ReferenceEquals(_archiveSuffixFormat, _legacyDateArchiveSuffixFormat) || ReferenceEquals(_archiveSuffixFormat, _legacySequenceArchiveSuffixFormat)) | ||
| { | ||
| ArchiveSuffixFormat = _archiveNumbering.IndexOf("date", StringComparison.OrdinalIgnoreCase) >= 0 ? _legacyDateArchiveSuffixFormat : _legacySequenceArchiveSuffixFormat; | ||
| ArchiveSuffixFormat = archiveNumbering.IndexOf("date", StringComparison.OrdinalIgnoreCase) >= 0 ? _legacyDateArchiveSuffixFormat : _legacySequenceArchiveSuffixFormat; |
There was a problem hiding this comment.
| ArchiveSuffixFormat = archiveNumbering.IndexOf("date", StringComparison.OrdinalIgnoreCase) >= 0 ? _legacyDateArchiveSuffixFormat : _legacySequenceArchiveSuffixFormat; | |
| ArchiveSuffixFormat = archiveNumbering.Contains("date", StringComparison.OrdinalIgnoreCase) ? _legacyDateArchiveSuffixFormat : _legacySequenceArchiveSuffixFormat; |
this can be simplified
There was a problem hiding this comment.
Recall that Contains with StringComparison is not available on NET35, which is why using IndexOf. But thank you for noticing.



No description provided.