[CHANGE] event console own component
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
<MudSwitch @bind-Value="@_autoScroll">Auto-scroll</MudSwitch>
|
||||
</MudStack>
|
||||
<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">
|
||||
@TimeZoneInfo.ConvertTime(serviceEvent.DateUtc, _timeZone)
|
||||
<span class="log-severity @GetLogClass(serviceEvent)">@serviceEvent.Severity</span> [<span style="color: #1565c0">@serviceEvent.Source</span>]
|
||||
|
@@ -9,7 +9,7 @@ namespace Manager.App.Components.Application.System;
|
||||
|
||||
public partial class EventConsole : ComponentBase
|
||||
{
|
||||
private const int BatchDelayMs = 1000;
|
||||
private const int BatchDelayMs = 2000;
|
||||
private List<ServiceEvent> _serviceEvents = [];
|
||||
private readonly List<ServiceEvent> _batchBuffer = [];
|
||||
private readonly SemaphoreSlim _batchLock = new(1, 1);
|
||||
@@ -17,6 +17,7 @@ public partial class EventConsole : ComponentBase
|
||||
private bool _autoScroll = true;
|
||||
private CancellationTokenSource _cts = new();
|
||||
private TimeZoneInfo _timeZone = TimeZoneInfo.Local;
|
||||
private Virtualize<ServiceEvent>? _virtualize;
|
||||
|
||||
[Parameter]
|
||||
public List<ServiceEvent> InitialEvents { get; set; } = [];
|
||||
@@ -109,13 +110,18 @@ public partial class EventConsole : ComponentBase
|
||||
_serviceEvents.AddRange(batch);
|
||||
_lastBatchUpdate = DateTime.UtcNow;
|
||||
|
||||
await InvokeAsync(StateHasChanged);
|
||||
if (_virtualize != null)
|
||||
{
|
||||
await _virtualize.RefreshDataAsync();
|
||||
}
|
||||
|
||||
if (_autoScroll)
|
||||
{
|
||||
await JsRuntime.InvokeVoidAsync("scrollToBottom", _consoleContainer);
|
||||
}
|
||||
|
||||
await InvokeAsync(StateHasChanged);
|
||||
|
||||
_updateScheduled = false;
|
||||
break;
|
||||
}
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
@@ -1,6 +1,8 @@
|
||||
window.scrollToBottom = (element) => {
|
||||
if (element) {
|
||||
requestAnimationFrame(function () {
|
||||
element.scroll({ top: element.scrollHeight, behavior: 'smooth' });
|
||||
})
|
||||
}
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user