refactor: move debug-only logic to runtime condition in SerilogDemo page
This commit is contained in:
@@ -2,7 +2,8 @@
|
|||||||
@inject ILogger<SerilogDemo> Logger
|
@inject ILogger<SerilogDemo> Logger
|
||||||
@inject IJSRuntime JSRuntime
|
@inject IJSRuntime JSRuntime
|
||||||
|
|
||||||
#if DEBUG
|
@if (_isDebug)
|
||||||
|
{
|
||||||
<div class="serilog-demo-container">
|
<div class="serilog-demo-container">
|
||||||
<div class="header-card glass-panel">
|
<div class="header-card glass-panel">
|
||||||
<div class="header-content">
|
<div class="header-content">
|
||||||
@@ -88,30 +89,41 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
#else
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
<div class="serilog-demo-container">
|
<div class="serilog-demo-container">
|
||||||
<div class="glass-panel" style="text-align: center; padding: 3rem;">
|
<div class="glass-panel" style="text-align: center; padding: 3rem;">
|
||||||
<h2>Diagnostics Unavailable</h2>
|
<h2>Diagnostics Unavailable</h2>
|
||||||
<p>This page is only available in DEBUG builds.</p>
|
<p>This page is only available in DEBUG builds.</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
#endif
|
}
|
||||||
|
|
||||||
|
|
||||||
@code {
|
@code {
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
|
private readonly bool _isDebug = true;
|
||||||
|
#else
|
||||||
|
private readonly bool _isDebug = false;
|
||||||
|
#endif
|
||||||
|
|
||||||
private void LogInfo()
|
private void LogInfo()
|
||||||
{
|
{
|
||||||
|
#if DEBUG
|
||||||
Logger.LogInformation("Structured native log triggered by user from SerilogDemo. Button: LogInfo");
|
Logger.LogInformation("Structured native log triggered by user from SerilogDemo. Button: LogInfo");
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LogWarning()
|
private void LogWarning()
|
||||||
{
|
{
|
||||||
|
#if DEBUG
|
||||||
Logger.LogWarning("Potential warning log triggered from Blazor razor component at {Time}", DateTime.UtcNow);
|
Logger.LogWarning("Potential warning log triggered from Blazor razor component at {Time}", DateTime.UtcNow);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LogError()
|
private void LogError()
|
||||||
{
|
{
|
||||||
|
#if DEBUG
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException("Simulated native C# operation exception triggered in Diagnostic dashboard.");
|
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!");
|
Logger.LogError(ex, "Captured exception successfully in native Serilog pipeline!");
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task TriggerJsLog()
|
private async Task TriggerJsLog()
|
||||||
{
|
{
|
||||||
|
#if DEBUG
|
||||||
await JSRuntime.InvokeVoidAsync("console.log", "Intercepted JS console statement from Blazor WebView interop trigger!");
|
await JSRuntime.InvokeVoidAsync("console.log", "Intercepted JS console statement from Blazor WebView interop trigger!");
|
||||||
|
#endif
|
||||||
|
await Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task TriggerJsException()
|
private async Task TriggerJsException()
|
||||||
{
|
{
|
||||||
|
#if DEBUG
|
||||||
await JSRuntime.InvokeVoidAsync("eval", "throw new Error('Simulated runtime JS Exception triggered from Blazor UI button click!');");
|
await JSRuntime.InvokeVoidAsync("eval", "throw new Error('Simulated runtime JS Exception triggered from Blazor UI button click!');");
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
await Task.CompletedTask;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user