[CHANGE] event console own component

This commit is contained in:
max
2025-09-10 20:09:58 +02:00
parent 9be6f5be89
commit b1e5b0dc68
4 changed files with 12 additions and 25 deletions

View File

@@ -10,7 +10,7 @@
<MudSwitch @bind-Value="@_autoScroll">Auto-scroll</MudSwitch> <MudSwitch @bind-Value="@_autoScroll">Auto-scroll</MudSwitch>
</MudStack> </MudStack>
<div @ref="@_consoleContainer" class="console-container" @onwheel="OnUserScroll"> <div @ref="@_consoleContainer" class="console-container" @onwheel="OnUserScroll">
<Virtualize ItemsProvider="VirtualizedItemsProvider" Context="serviceEvent"> <Virtualize @ref="_virtualize" TItem="ServiceEvent" ItemsProvider="VirtualizedItemsProvider" Context="serviceEvent">
<div class="log-line"> <div class="log-line">
@TimeZoneInfo.ConvertTime(serviceEvent.DateUtc, _timeZone)&nbsp; @TimeZoneInfo.ConvertTime(serviceEvent.DateUtc, _timeZone)&nbsp;
<span class="log-severity @GetLogClass(serviceEvent)">@serviceEvent.Severity</span>&nbsp;[<span style="color: #1565c0">@serviceEvent.Source</span>]&nbsp; <span class="log-severity @GetLogClass(serviceEvent)">@serviceEvent.Severity</span>&nbsp;[<span style="color: #1565c0">@serviceEvent.Source</span>]&nbsp;

View File

@@ -9,7 +9,7 @@ namespace Manager.App.Components.Application.System;
public partial class EventConsole : ComponentBase public partial class EventConsole : ComponentBase
{ {
private const int BatchDelayMs = 1000; private const int BatchDelayMs = 2000;
private List<ServiceEvent> _serviceEvents = []; private List<ServiceEvent> _serviceEvents = [];
private readonly List<ServiceEvent> _batchBuffer = []; private readonly List<ServiceEvent> _batchBuffer = [];
private readonly SemaphoreSlim _batchLock = new(1, 1); private readonly SemaphoreSlim _batchLock = new(1, 1);
@@ -17,6 +17,7 @@ public partial class EventConsole : ComponentBase
private bool _autoScroll = true; private bool _autoScroll = true;
private CancellationTokenSource _cts = new(); private CancellationTokenSource _cts = new();
private TimeZoneInfo _timeZone = TimeZoneInfo.Local; private TimeZoneInfo _timeZone = TimeZoneInfo.Local;
private Virtualize<ServiceEvent>? _virtualize;
[Parameter] [Parameter]
public List<ServiceEvent> InitialEvents { get; set; } = []; public List<ServiceEvent> InitialEvents { get; set; } = [];
@@ -109,12 +110,17 @@ public partial class EventConsole : ComponentBase
_serviceEvents.AddRange(batch); _serviceEvents.AddRange(batch);
_lastBatchUpdate = DateTime.UtcNow; _lastBatchUpdate = DateTime.UtcNow;
await InvokeAsync(StateHasChanged); if (_virtualize != null)
{
await _virtualize.RefreshDataAsync();
}
if (_autoScroll) if (_autoScroll)
{ {
await JsRuntime.InvokeVoidAsync("scrollToBottom", _consoleContainer); await JsRuntime.InvokeVoidAsync("scrollToBottom", _consoleContainer);
} }
await InvokeAsync(StateHasChanged);
_updateScheduled = false; _updateScheduled = false;
break; break;

View File

@@ -1,21 +0,0 @@
using DotBased.Logging;
namespace Manager.App.Services.System;
public class TestService(ILogger<TestService> logger) : ExtendedBackgroundService("TestService", "Development service", logger, TimeSpan.FromMilliseconds(100))
{
protected override Task InitializeAsync(CancellationToken stoppingToken)
{
return Task.CompletedTask;
}
protected override Task ExecuteServiceAsync(CancellationToken stoppingToken)
{
LogEvent("TestService");
LogEvent($"Error {Guid.NewGuid()}", LogSeverity.Error);
LogEvent("Something went wrong!", LogSeverity.Warning);
LogEvent("Tracing.", LogSeverity.Trace);
LogEvent("Fatal error!", LogSeverity.Fatal);
return Task.CompletedTask;
}
}

View File

@@ -1,6 +1,8 @@
window.scrollToBottom = (element) => { window.scrollToBottom = (element) => {
if (element) { if (element) {
element.scroll({ top: element.scrollHeight, behavior: 'smooth' }); requestAnimationFrame(function () {
element.scroll({ top: element.scrollHeight, behavior: 'smooth' });
})
} }
}; };