Skip to content

Fix RichTextBox sink event loss during disposal - #41

Merged
vonhoff merged 1 commit into
masterfrom
maintenance
Sep 12, 2026
Merged

vonhoff merged 1 commit into
masterfrom
maintenance

Conversation

@vonhoff

@vonhoff vonhoff commented Sep 12, 2026 •

Copy link
Copy Markdown
Owner

The RichTextBox sink could display only the first of several rapidly emitted log events when the logger was immediately closed, especially when combined with the File sink.

This change drains the final buffered snapshot before stopping the sink’s processing task, preserving events emitted before disposal. It also adds regression coverage, and bumps the package version to 3.2.1

Copilot AI lite review requested due to automatic review settings September 12, 2026 17:52
@vonhoff vonhoff added this to the 3.3.0 milestone Sep 12, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

A critical disposal hang risk and dependency compatibility issue remain unresolved.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Fixes RichTextBox sink event loss during disposal by draining buffered events, adding regression coverage, and updating targets and package metadata.

Changes:

  • Flushes the final buffered snapshot during shutdown.
  • Adds sink lifecycle regression coverage.
  • Updates targets, dependencies, and package version.
File summaries
File Summary
Serilog.Sinks.RichTextBox.WinForms.Colored/Sinks/RichTextBoxForms/RichTextBoxSink.cs Adds final flushing; cancellation handling may allow disposal to hang.
Serilog.Sinks.RichTextBox.WinForms.Colored/Serilog.Sinks.RichTextBox.WinForms.Colored.csproj Updates package metadata; raises the Serilog minimum to 4.4.0 without documented justification.
Serilog.Sinks.RichTextBox.WinForms.Colored.Test/Serilog.Sinks.RichTextBox.WinForms.Colored.Test.csproj Updates test tooling and dependencies.
Serilog.Sinks.RichTextBox.WinForms.Colored.Test/Integration/SinkLifecycleTests.cs Adds disposal event-draining coverage.
Demo/Demo.csproj Updates demo dependencies.
Review details

Suppressed comments (1)

Serilog.Sinks.RichTextBox.WinForms.Colored/Sinks/RichTextBoxForms/RichTextBoxSink.cs:154

  • This call still does not synchronously apply the final snapshot: ProcessMessages runs on Task.Run, and SetRtf uses BeginInvoke when InvokeRequired is true, so this returns after only queuing the UI delegate. Dispose() waits for _processingTask but not that delegate; if the caller disposes the control immediately afterward, the handle can be destroyed before the callback runs and the final events are still lost. Shutdown needs to acknowledge the final UI callback without blocking the UI thread, and this path needs a test that disposes the control immediately.
                _richTextBox.SetRtf(builder.Rtf, _options.AutoScroll, stopping ? CancellationToken.None : token);
  • Files reviewed: 5/5 changed files
  • Comments generated: 2
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@vonhoff
vonhoff merged commit 72f270d into master Sep 12, 2026
1 check passed
@vonhoff
vonhoff deleted the maintenance branch September 12, 2026 18:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants