refactor: move debug-only logic to runtime condition in SerilogDemo page

This commit is contained in:
2026-05-26 20:15:19 +02:00
parent b867d08e63
commit a9a670d776
@@ -2,7 +2,8 @@
@inject ILogger<SerilogDemo> Logger
@inject IJSRuntime JSRuntime
#if DEBUG
@if (_isDebug)
{
<div class="serilog-demo-container">
<div class="header-card glass-panel">
<div class="header-content">
@@ -88,30 +89,41 @@
</div>
</div>
</div>
#else
}
else
{
<div class="serilog-demo-container">
<div class="glass-panel" style="text-align: center; padding: 3rem;">
<h2>Diagnostics Unavailable</h2>
<p>This page is only available in DEBUG builds.</p>
</div>
</div>
#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;
}
}