Skip to content

Commit 0fc797d

Browse files
authored
Merge pull request #26 from vonhoff/25-expanding-the-maxloglines-constraint
Config adjustments and optimizations
2 parents 1af5cb9 + 5bd4716 commit 0fc797d

File tree

5 files changed

+41
-95
lines changed

5 files changed

+41
-95
lines changed

CHANGES.md

Lines changed: 7 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,14 @@
1-
## Release Notes - Serilog.Sinks.RichTextBox.WinForms.Colored v3.0.0
1+
## Release Notes - Serilog.Sinks.RichTextBox.WinForms.Colored v3.0.1
22

3-
### Major Release - Breaking Changes
3+
### Minor Release
44

5-
This major release focuses on performance optimization, UI stability, and streamlined configuration while simplifying the configuration API.
5+
This minor release focuses on config improvements and performance optimization.
66

7-
### Breaking Changes
7+
### What Changed
88

9-
- **Simplified Configuration Options**: Reduced configurable options to focus only on the most relevant and commonly used settings:
10-
- Removed `messageBatchSize` parameter (no longer needed)
11-
- Removed `messagePendingInterval` parameter (no longer needed)
12-
- Renamed `appliedTheme` parameter to `theme` for consistency
13-
14-
- **Theme System Overhaul**: Complete redesign of the theme system to align with the Serilog WPF sink. Previous theme names (`Dark`, `Light`, `DarkClassic`, `LightClassic`) have been replaced with new theme presets. All themes now include WCAG compliance with proper contrast ratio.
15-
16-
- **Enhanced Memory Management**: The `maxLogLines` parameter now has improved validation (1-512 range) with a default of 256 lines to ensure optimal performance. While not mandatory, proper configuration is recommended to prevent performance degradation from excessive log entries in the WinForms control.
17-
18-
### New Theme System
19-
20-
Available built-in themes:
21-
22-
| Theme | Description |
23-
|-----------------------------|------------------------------------------------------------------------------|
24-
| `ThemePresets.Literate` | Styled to replicate the default theme of Serilog.Sinks.Console (default) |
25-
| `ThemePresets.Grayscale` | A theme using only shades of gray, white, and black |
26-
| `ThemePresets.Colored` | A theme based on the original Serilog.Sinks.ColoredConsole sink |
27-
| `ThemePresets.Luminous` | A new light theme with high contrast for accessibility |
28-
29-
The themes based on the original sinks are slightly adjusted to be WCAG compliant, ensuring that the contrast ratio between text and background colors is at least 4.5:1. `Luminous` is a new theme specifically created for this sink.
30-
31-
### Bug Fixes
32-
33-
- **Fixed UI Freezing**: Resolved critical UI freeze issues caused by SystemEvents when using RichTextBox controls on background threads.
34-
35-
- **Fixed Auto-scroll on .NET Framework**: Corrected auto-scroll behavior that wasn't working properly on .NET Framework applications.
36-
37-
### Performance Improvements
38-
39-
- **Optimized Rendering Logic**: Removed the off-screen RichTextBox dependency and improved the rendering pipeline for better performance and reduced memory usage.
40-
41-
- **Streamlined Processing**: Removed unnecessary batching parameters to simplify internal processing logic.
42-
43-
### Migration Guide
44-
45-
Due to breaking changes, please update your existing configurations:
46-
47-
1. **Update Theme Names**: Replace old theme names with new equivalents:
48-
- `Dark` or `DarkClassic``ThemePresets.Colored` or `ThemePresets.Grayscale` or `ThemePresets.Literate`
49-
- `Light` or `LightClassic``ThemePresets.Luminous`
50-
51-
2. **Update Parameter Names**:
52-
- `appliedTheme``theme`
53-
- Remove `messageBatchSize` and `messagePendingInterval` parameters (no longer supported)
54-
55-
I recommend pairing this sink with a file sink for persistent logging storage, as it's not practical to have thousands of log entries displayed in a RichTextBox control.
56-
57-
### Recommended Configuration
58-
59-
```csharp
60-
Log.Logger = new LoggerConfiguration()
61-
.WriteTo.RichTextBox(richTextBox1,
62-
theme: ThemePresets.Literate,
63-
maxLogLines: 64) // Optional, defaults to 256
64-
.WriteTo.File("logs/app-.txt", rollingInterval: RollingInterval.Day) // Recommended for persistence
65-
.CreateLogger();
66-
```
67-
68-
### Full Changelog
69-
70-
- Reduced configurable options to only the most relevant ones (breaking change)
71-
- Renamed `appliedTheme` parameter to `theme` (breaking change)
72-
- Removed `messageBatchSize` and `messagePendingInterval` parameters (breaking change)
73-
- Completely redesigned theme system with new theme names and WCAG compliance (breaking change)
74-
- Added new `Luminous` theme for high contrast accessibility
75-
- Enhanced `maxLogLines` validation with 1-512 range limit
76-
- Fixed UI freeze caused by SystemEvents on background-thread RichTextBox
77-
- Optimized performance by removing the off-screen RichTextBox and improving rendering logic
78-
- Fixed auto-scroll issue on .NET Framework
9+
- Adjusted MaxLogLines limit From 512 to 2048 lines.
10+
- Fixed a bug where the RichTextBox would not persist the zoom factor.
11+
- Optimized the Concurrent Circular Buffer
7912

8013
### Resources
8114

Serilog.Sinks.RichTextBox.WinForms.Colored/Serilog.Sinks.RichTextBox.WinForms.Colored.csproj

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,11 @@
2222
<TargetFrameworks>net462;net471;net6.0-windows;net8.0-windows;net9.0-windows;netcoreapp3.0-windows;netcoreapp3.1-windows</TargetFrameworks>
2323
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
2424
<UseWindowsForms>true</UseWindowsForms>
25-
<Version>3.0.0</Version>
25+
<Version>3.0.1</Version>
2626
<PackageReleaseNotes>
27-
- Reduced configurable options to only the most relevant ones (breaking change).
28-
- Aligned theme colors with Serilog WPF sink including WCAG compliance (breaking change).
29-
- Fixed UI freeze caused by SystemEvents on background-thread RichTextBox.
30-
- Optimized performance by removing the off-screen RichTextBox and improving rendering logic.
31-
- Fixed auto-scroll issue on .NET Framework.
27+
- Adjusted MaxLogLines constraint from 512 to 2048 lines.
28+
- Fixed bug where the RTB control would not persist the zoom factor.
29+
- Minor improvements to the concurrent circular buffer.
3230

3331
See repository for more information:
3432
https://github.com/vonhoff/Serilog.Sinks.RichTextBox.WinForms.Colored

Serilog.Sinks.RichTextBox.WinForms.Colored/Sinks/RichTextBoxForms/Collections/ConcurrentCircularBuffer.cs

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,39 @@ namespace Serilog.Sinks.RichTextBoxForms.Collections
44
{
55
internal sealed class ConcurrentCircularBuffer<T>
66
{
7+
private readonly object _sync = new();
78
private readonly T[] _buffer;
89
private readonly int _capacity;
910
private int _head;
1011
private int _count;
1112

12-
private readonly object _sync = new();
13-
1413
public ConcurrentCircularBuffer(int capacity)
1514
{
1615
_capacity = capacity > 0 ? capacity : 1;
1716
_buffer = new T[_capacity];
18-
_head = 0;
19-
_count = 0;
2017
}
2118

2219
public void Add(T item)
2320
{
2421
lock (_sync)
2522
{
26-
var tail = (_head + _count) % _capacity;
27-
_buffer[tail] = item;
23+
var tail = _head + _count;
24+
if (tail >= _capacity)
25+
{
26+
tail -= _capacity;
27+
}
2828

29+
_buffer[tail] = item;
2930
if (_count == _capacity)
3031
{
31-
_head = (_head + 1) % _capacity;
32+
if (++_head == _capacity)
33+
{
34+
_head = 0;
35+
}
3236
}
3337
else
3438
{
35-
_count++;
39+
++_count;
3640
}
3741
}
3842
}
@@ -42,13 +46,18 @@ public void TakeSnapshot(List<T> target)
4246
lock (_sync)
4347
{
4448
target.Clear();
45-
target.Capacity = _count;
4649

47-
for (var i = 0; i < _count; i++)
50+
for (var i = 0; i < _count; ++i)
4851
{
49-
target.Add(_buffer[(_head + i) % _capacity]);
52+
var index = _head + i;
53+
if (index >= _capacity)
54+
{
55+
index -= _capacity;
56+
}
57+
58+
target.Add(_buffer[index]);
5059
}
5160
}
5261
}
5362
}
54-
}
63+
}

Serilog.Sinks.RichTextBox.WinForms.Colored/Sinks/RichTextBoxForms/Extensions/RichTextBoxExtensions.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public static void SetRtf(this RichTextBox richTextBox, string rtf, bool autoScr
6868
private static void SetRtfInternal(RichTextBox richTextBox, string rtf, bool autoScroll)
6969
{
7070
richTextBox.Suspend();
71-
71+
var originalZoomFactor = richTextBox.ZoomFactor;
7272
var scrollPoint = new Point();
7373

7474
if (!autoScroll)
@@ -78,6 +78,12 @@ private static void SetRtfInternal(RichTextBox richTextBox, string rtf, bool aut
7878

7979
richTextBox.Rtf = rtf;
8080

81+
// Re-apply the zoom level, as assigning to the Rtf property resets it back to 1.0.
82+
if (Math.Abs(richTextBox.ZoomFactor - originalZoomFactor) > float.Epsilon)
83+
{
84+
richTextBox.ZoomFactor = originalZoomFactor;
85+
}
86+
8187
if (!autoScroll)
8288
{
8389
SendMessage(richTextBox.Handle, EM_SETSCROLLPOS, 0, ref scrollPoint);

Serilog.Sinks.RichTextBox.WinForms.Colored/Sinks/RichTextBoxForms/RichTextBoxSinkOptions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class RichTextBoxSinkOptions
3232
/// </summary>
3333
/// <param name="theme">The colour theme applied when rendering individual message tokens.</param>
3434
/// <param name="autoScroll">When <c>true</c> (default) the target control scrolls automatically to the most recent log line.</param>
35-
/// <param name="maxLogLines">Maximum number of log events retained in the in-memory circular buffer and rendered in the control. Must be between 1 and 10,000 (default: 256).</param>
35+
/// <param name="maxLogLines">Maximum number of log events retained in the in-memory circular buffer and rendered in the control. Must be between 1 and 2048 (default: 256).</param>
3636
/// <param name="flushInterval">Timeout, in milliseconds, after which buffered events are flushed to the control if a batch has not yet been triggered. Must be between 250ms and 30 seconds (default: 500ms).</param>
3737
/// <param name="outputTemplate">Serilog output template that controls textual formatting of each log event.</param>
3838
/// <param name="formatProvider">Optional culture-specific or custom formatting provider used when rendering scalar values; <c>null</c> for the invariant culture.</param>
@@ -60,7 +60,7 @@ public int MaxLogLines
6060
private set => _maxLogLines = value switch
6161
{
6262
< 1 => 1,
63-
> 512 => 512,
63+
> 2048 => 2048,
6464
_ => value
6565
};
6666
}

0 commit comments

Comments
 (0)