Skip to content

Commit 8765e1a

Browse files
committed
feat: add Serilog sink for WinForms RichTextBox with theme support
1 parent 3ba6fa4 commit 8765e1a

File tree

4 files changed

+181
-113
lines changed

4 files changed

+181
-113
lines changed

source/RevitDevTool/RevitDevTool.csproj

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,14 @@
5555
<PackageReference Include="Nice3point.Revit.Api.UIFramework" Version="$(RevitVersion).*" />
5656
<PackageReference Include="Nice3point.Revit.Api.AdWindows" Version="$(RevitVersion).*" />
5757

58-
<!-- MVVM -->
58+
<!-- UI -->
5959
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.0" />
60+
<PackageReference Include="Serilog.Sinks.RichTextBox.WinForms.Colored" Version="3.1.3" />
6061

6162
<!-- Utils -->
6263
<PackageReference Include="JetBrains.Annotations" Version="2024.3.0" />
6364
<PackageReference Include="PolySharp" Version="*" PrivateAssets="All" IncludeAssets="runtime; build; native; contentfiles; analyzers; buildtransitive" />
6465
<PackageReference Include="ILRepack" Version="2.0.41" />
65-
66-
<!-- Logging -->
67-
<PackageReference Include="Serilog.Sinks.RichTextBox.WinForms.Colored" Version="3.1.3" />
6866
</ItemGroup>
6967

7068
<ItemGroup>
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
using Serilog.Sinks.RichTextBoxForms.Themes;
2+
using Color = System.Drawing.Color;
3+
4+
namespace RevitDevTool.Theme;
5+
6+
public static class AdaptiveThemePresets
7+
{
8+
private static readonly Color LightBackground = Color.FromArgb(250, 250, 250);
9+
private static readonly Color DarkBackground = Color.FromArgb(30, 30, 30);
10+
11+
/// <summary>
12+
/// Enhanced dark theme with better contrast and readability - foreground colors only
13+
/// </summary>
14+
public static Serilog.Sinks.RichTextBoxForms.Themes.Theme EnhancedDark { get; } = new(
15+
new Style(Color.FromArgb(240, 240, 240), Color.FromArgb(30, 30, 30)),
16+
new Dictionary<StyleToken, Style>
17+
{
18+
[StyleToken.Text] = new(Color.FromArgb(240, 240, 240), DarkBackground),
19+
[StyleToken.SecondaryText] = new(Color.FromArgb(180, 180, 180), DarkBackground),
20+
[StyleToken.TertiaryText] = new(Color.FromArgb(160, 160, 160), DarkBackground),
21+
[StyleToken.Invalid] = new(Color.FromArgb(255, 220, 120), DarkBackground),
22+
[StyleToken.Null] = new(Color.FromArgb(180, 180, 255), DarkBackground),
23+
[StyleToken.Name] = new(Color.FromArgb(255, 200, 255), DarkBackground),
24+
[StyleToken.String] = new(Color.FromArgb(120, 255, 170), DarkBackground),
25+
[StyleToken.Number] = new(Color.FromArgb(255, 200, 120), DarkBackground),
26+
[StyleToken.Boolean] = new(Color.FromArgb(170, 220, 255), DarkBackground),
27+
[StyleToken.Scalar] = new(Color.FromArgb(170, 255, 220), DarkBackground),
28+
[StyleToken.LevelVerbose] = new(Color.FromArgb(140, 140, 140), DarkBackground),
29+
[StyleToken.LevelDebug] = new(Color.FromArgb(170, 170, 170), DarkBackground),
30+
[StyleToken.LevelInformation] = new(Color.FromArgb(120, 170, 255), DarkBackground),
31+
[StyleToken.LevelWarning] = new(Color.FromArgb(255, 220, 70), DarkBackground),
32+
[StyleToken.LevelError] = new(Color.FromArgb(255, 100, 100), DarkBackground),
33+
[StyleToken.LevelFatal] = new(Color.FromArgb(255, 80, 80), DarkBackground)
34+
});
35+
36+
/// <summary>
37+
/// Enhanced light theme with better contrast and readability - foreground colors only
38+
/// </summary>
39+
public static Serilog.Sinks.RichTextBoxForms.Themes.Theme EnhancedLight { get; } = new(
40+
new Style(Color.FromArgb(40, 40, 40), Color.FromArgb(250, 250, 250)),
41+
new Dictionary<StyleToken, Style>
42+
{
43+
[StyleToken.Text] = new(Color.FromArgb(40, 40, 40), LightBackground),
44+
[StyleToken.SecondaryText] = new(Color.FromArgb(80, 80, 80), LightBackground),
45+
[StyleToken.TertiaryText] = new(Color.FromArgb(120, 120, 120), LightBackground),
46+
[StyleToken.Invalid] = new(Color.FromArgb(180, 80, 0), LightBackground),
47+
[StyleToken.Null] = new(Color.FromArgb(80, 80, 200), LightBackground),
48+
[StyleToken.Name] = new(Color.FromArgb(150, 0, 150), LightBackground),
49+
[StyleToken.String] = new(Color.FromArgb(0, 120, 0), LightBackground),
50+
[StyleToken.Number] = new(Color.FromArgb(180, 80, 0), LightBackground),
51+
[StyleToken.Boolean] = new(Color.FromArgb(0, 80, 180), LightBackground),
52+
[StyleToken.Scalar] = new(Color.FromArgb(0, 140, 100), LightBackground),
53+
[StyleToken.LevelVerbose] = new(Color.FromArgb(120, 120, 120), LightBackground),
54+
[StyleToken.LevelDebug] = new(Color.FromArgb(80, 80, 80), LightBackground),
55+
[StyleToken.LevelInformation] = new(Color.FromArgb(0, 80, 180), LightBackground),
56+
[StyleToken.LevelWarning] = new(Color.FromArgb(200, 140, 0), LightBackground),
57+
[StyleToken.LevelError] = new(Color.FromArgb(200, 60, 60), LightBackground),
58+
[StyleToken.LevelFatal] = new(Color.FromArgb(150, 30, 30), LightBackground)
59+
});
60+
61+
/// <summary>
62+
/// Soft dark theme with muted colors for extended use
63+
/// </summary>
64+
public static Serilog.Sinks.RichTextBoxForms.Themes.Theme SoftDark { get; } = new(
65+
new Style(Color.FromArgb(200, 200, 200), Color.FromArgb(25, 25, 25)),
66+
new Dictionary<StyleToken, Style>
67+
{
68+
[StyleToken.Text] = new(Color.FromArgb(200, 200, 200), DarkBackground),
69+
[StyleToken.SecondaryText] = new(Color.FromArgb(150, 150, 150), DarkBackground),
70+
[StyleToken.TertiaryText] = new(Color.FromArgb(120, 120, 120), DarkBackground),
71+
[StyleToken.Invalid] = new(Color.FromArgb(220, 180, 80), DarkBackground),
72+
[StyleToken.Null] = new(Color.FromArgb(130, 130, 220), DarkBackground),
73+
[StyleToken.Name] = new(Color.FromArgb(220, 160, 220), DarkBackground),
74+
[StyleToken.String] = new(Color.FromArgb(120, 200, 140), DarkBackground),
75+
[StyleToken.Number] = new(Color.FromArgb(220, 160, 100), DarkBackground),
76+
[StyleToken.Boolean] = new(Color.FromArgb(130, 180, 220), DarkBackground),
77+
[StyleToken.Scalar] = new(Color.FromArgb(140, 200, 180), DarkBackground),
78+
[StyleToken.LevelVerbose] = new(Color.FromArgb(100, 100, 100), DarkBackground),
79+
[StyleToken.LevelDebug] = new(Color.FromArgb(130, 130, 130), DarkBackground),
80+
[StyleToken.LevelInformation] = new(Color.FromArgb(120, 160, 220), DarkBackground),
81+
[StyleToken.LevelWarning] = new(Color.FromArgb(220, 180, 60), DarkBackground),
82+
[StyleToken.LevelError] = new(Color.FromArgb(180, 60, 60), DarkBackground),
83+
[StyleToken.LevelFatal] = new(Color.FromArgb(150, 40, 40), DarkBackground)
84+
85+
});
86+
87+
/// <summary>
88+
/// High contrast light theme for better accessibility
89+
/// </summary>
90+
public static Serilog.Sinks.RichTextBoxForms.Themes.Theme HighContrastLight { get; } = new(
91+
new Style(Color.FromArgb(20, 20, 20), Color.FromArgb(255, 255, 255)),
92+
new Dictionary<StyleToken, Style>
93+
{
94+
[StyleToken.Text] = new(Color.FromArgb(20, 20, 20), LightBackground),
95+
[StyleToken.SecondaryText] = new(Color.FromArgb(60, 60, 60), LightBackground),
96+
[StyleToken.TertiaryText] = new(Color.FromArgb(100, 100, 100), LightBackground),
97+
[StyleToken.Invalid] = new(Color.FromArgb(180, 80, 0), LightBackground),
98+
[StyleToken.Null] = new(Color.FromArgb(60, 60, 180), LightBackground),
99+
[StyleToken.Name] = new(Color.FromArgb(120, 0, 120), LightBackground),
100+
[StyleToken.String] = new(Color.FromArgb(0, 100, 0), LightBackground),
101+
[StyleToken.Number] = new(Color.FromArgb(160, 60, 0), LightBackground),
102+
[StyleToken.Boolean] = new(Color.FromArgb(0, 60, 160), LightBackground),
103+
[StyleToken.Scalar] = new(Color.FromArgb(0, 120, 80), LightBackground),
104+
[StyleToken.LevelVerbose] = new(Color.FromArgb(100, 100, 100), LightBackground),
105+
[StyleToken.LevelDebug] = new(Color.FromArgb(60, 60, 60), LightBackground),
106+
[StyleToken.LevelInformation] = new(Color.FromArgb(0, 60, 160), LightBackground),
107+
[StyleToken.LevelWarning] = new(Color.FromArgb(255, 200, 80), LightBackground),
108+
[StyleToken.LevelError] = new(Color.FromArgb(180, 40, 40), LightBackground),
109+
[StyleToken.LevelFatal] = new(Color.FromArgb(120, 20, 20), LightBackground)
110+
});
111+
}

source/RevitDevTool/View/TraceLog.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public partial class TraceLog : IDisposable
1515
public TraceLog()
1616
{
1717
InitializeComponent();
18-
DataContext = new TraceLogViewModel(this);
18+
DataContext = new TraceLogViewModel();
1919
#if REVIT2024_OR_GREATER
2020
ApplicationTheme.CurrentTheme.PropertyChanged += ApplyTheme;
2121
#endif

0 commit comments

Comments
 (0)