From a9a670d776f767f33a2fb13b90f8b828afca07db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Jasi=C5=84ski?= Date: Tue, 26 May 2026 20:15:19 +0200 Subject: [PATCH] refactor: move debug-only logic to runtime condition in SerilogDemo page --- .../Pages/SerilogDemo.razor | 190 ++++++++++-------- 1 file changed, 104 insertions(+), 86 deletions(-) diff --git a/src/NexusReader.UI.Shared/Pages/SerilogDemo.razor b/src/NexusReader.UI.Shared/Pages/SerilogDemo.razor index 2c6159c..6166989 100644 --- a/src/NexusReader.UI.Shared/Pages/SerilogDemo.razor +++ b/src/NexusReader.UI.Shared/Pages/SerilogDemo.razor @@ -2,116 +2,128 @@ @inject ILogger Logger @inject IJSRuntime JSRuntime -#if DEBUG -
-
-
- -
-

Serilog Logging Infrastructure

-

Production-grade diagnostic pipeline for unified native & web logs

+@if (_isDebug) +{ +
+
+
+ +
+

Serilog Logging Infrastructure

+

Production-grade diagnostic pipeline for unified native & web logs

+
+
+
+ + Pipeline Active
-
- - Pipeline Active -
-
-
- -
+
+ +
+
+ +

Native .NET Logs (C#)

+
+

Trigger structured C# logs using Dependency Injected ILogger.

+
+ + + +
+
+ + +
+
+ +

Blazor / JS WebView Logs

+
+

Trigger logs from JavaScript to verify the interop error capture bridge.

+
+ + +
+
+
+ + +
- -

Native .NET Logs (C#)

+ +

Pipeline Diagnostics

-

Trigger structured C# logs using Dependency Injected ILogger.

-
- - - -
-
- - -
-
- -

Blazor / JS WebView Logs

-
-

Trigger logs from JavaScript to verify the interop error capture bridge.

-
- - +
+
+ Rolling Daily File Sandbox Path + AppDataDirectory/logs/log-*.txt +
+
+ Active Configuration Provider + Serilog.Settings.Configuration (appsettings.json) +
+
+ Native Apple Console Sink + Serilog.Sinks.Debug (conditional compilation) +
+
+ Native Android Logcat Sink + AndroidLogcatSink (direct JNI bindings) +
- - -
-
- -

Pipeline Diagnostics

-
-
-
- Rolling Daily File Sandbox Path - AppDataDirectory/logs/log-*.txt -
-
- Active Configuration Provider - Serilog.Settings.Configuration (appsettings.json) -
-
- Native Apple Console Sink - Serilog.Sinks.Debug (conditional compilation) -
-
- Native Android Logcat Sink - AndroidLogcatSink (direct JNI bindings) -
+} +else +{ +
+
+

Diagnostics Unavailable

+

This page is only available in DEBUG builds.

-
-#else -
-
-

Diagnostics Unavailable

-

This page is only available in DEBUG builds.

-
-
-#endif - +} @code { #if DEBUG + private readonly bool _isDebug = true; +#else + private readonly bool _isDebug = false; +#endif + private void LogInfo() { +#if DEBUG Logger.LogInformation("Structured native log triggered by user from SerilogDemo. Button: LogInfo"); +#endif } private void LogWarning() { +#if DEBUG Logger.LogWarning("Potential warning log triggered from Blazor razor component at {Time}", DateTime.UtcNow); +#endif } private void LogError() { +#if DEBUG try { throw new InvalidOperationException("Simulated native C# operation exception triggered in Diagnostic dashboard."); @@ -120,16 +132,22 @@ { Logger.LogError(ex, "Captured exception successfully in native Serilog pipeline!"); } +#endif } private async Task TriggerJsLog() { +#if DEBUG await JSRuntime.InvokeVoidAsync("console.log", "Intercepted JS console statement from Blazor WebView interop trigger!"); +#endif + await Task.CompletedTask; } private async Task TriggerJsException() { +#if DEBUG await JSRuntime.InvokeVoidAsync("eval", "throw new Error('Simulated runtime JS Exception triggered from Blazor UI button click!');"); - } #endif + await Task.CompletedTask; + } }