MemoryTarget - Apply MaxLogsCount limit on next LogEvent#6023
MemoryTarget - Apply MaxLogsCount limit on next LogEvent#6023
Conversation
WalkthroughUpdates MemoryTarget’s internal ThreadSafeList: modifies Add logic to purge excess items in a loop before appending, and restores a locking GetEnumerator that yields items safely during iteration. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor Caller
participant ThreadSafeList as ThreadSafeList<T>
participant InnerList as Inner List
Caller->>ThreadSafeList: Add(item, maxListCount)
activate ThreadSafeList
ThreadSafeList->>ThreadSafeList: lock()
loop while Count ≥ maxListCount
ThreadSafeList->>InnerList: RemoveAt(0)
end
ThreadSafeList->>InnerList: Add(item)
ThreadSafeList-->>ThreadSafeList: unlock()
deactivate ThreadSafeList
Caller->>ThreadSafeList: GetEnumerator()
activate ThreadSafeList
ThreadSafeList->>ThreadSafeList: lock()
Note over ThreadSafeList: Yield items under lock
ThreadSafeList-->>Caller: IEnumerator<T>
ThreadSafeList-->>ThreadSafeList: unlock() on completion
deactivate ThreadSafeList
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/NLog/Targets/MemoryTarget.cs(2 hunks)
🔇 Additional comments (1)
src/NLog/Targets/MemoryTarget.cs (1)
231-238: LGTM – Enumeration correctly holds lock.The restored
GetEnumerator()implementation correctly holds the lock during the entire enumeration (until the iterator completes or is disposed), which matches the documented behavior in the XML comments at lines 87-88 warning that enumeration blocks writes.
|



See also #6022