@page "/serilog-demo" @inject ILogger Logger @inject IJSRuntime JSRuntime @if (_isDebug) {

Serilog Logging Infrastructure

Production-grade diagnostic pipeline for unified native & web logs

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.

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.

} @code { // Compile-time check ensures _isDebug is baked as false in Release/Test/Production builds, // which completely bypasses/strips rendering of the diagnostic UI and avoids exposing internal controls. #if DEBUG private readonly bool _isDebug = true; #else private readonly bool _isDebug = false; #endif private void LogInfo() { Logger.LogInformation("Structured native log triggered by user from SerilogDemo. Button: LogInfo"); } private void LogWarning() { Logger.LogWarning("Potential warning log triggered from Blazor razor component at {Time}", DateTime.UtcNow); } private void LogError() { try { throw new InvalidOperationException("Simulated native C# operation exception triggered in Diagnostic dashboard."); } catch (Exception ex) { Logger.LogError(ex, "Captured exception successfully in native Serilog pipeline!"); } } private async Task TriggerJsLog() { try { await JSRuntime.InvokeVoidAsync("console.log", "Intercepted JS console statement from Blazor WebView interop trigger!"); } catch (Exception ex) { Logger.LogWarning(ex, "Failed to execute console.log from diagnostic panel."); } } private async Task TriggerJsException() { try { // Triggers a TypeError by invoking a non-existent method, which is completely CSP-compliant and works without eval() await JSRuntime.InvokeVoidAsync("window.nonExistentFunctionTriggeringException"); } catch (Exception ex) { Logger.LogError(ex, "Simulated runtime JS Exception triggered and captured in Blazor UI"); try { await JSRuntime.InvokeVoidAsync("console.error", $"Simulated JS Exception: {ex.Message}"); } catch { } } } }