2022-01-21 13:54:22 +00:00
|
|
|
@using NLog
|
|
|
|
@using NLog.Targets
|
2022-01-28 10:29:38 +00:00
|
|
|
@using Wabbajack.App.Blazor.Utility
|
|
|
|
@using System.Reactive.Linq
|
2022-01-20 08:34:38 +00:00
|
|
|
@namespace Wabbajack.App.Blazor.Components
|
2022-01-28 11:58:28 +00:00
|
|
|
@implements IDisposable
|
2022-01-20 08:34:38 +00:00
|
|
|
|
2022-01-17 16:45:52 +00:00
|
|
|
<div id="virtual-logger">
|
2022-01-28 11:58:28 +00:00
|
|
|
<Virtualize Items="_logs" Context="logItem" OverscanCount="5" ItemSize="24">
|
|
|
|
<span style="height: 24px">@logItem</span>
|
|
|
|
</Virtualize>
|
2022-01-17 16:45:52 +00:00
|
|
|
</div>
|
|
|
|
|
|
|
|
@code {
|
|
|
|
// TODO: [Low] More parameters to customise the logger. E.g. Reverse order.
|
|
|
|
// TODO: [High] Find a way to auto-scroll. (JS interop?)
|
|
|
|
|
2022-01-28 10:29:38 +00:00
|
|
|
private UiLoggerTarget? _loggerTarget;
|
2022-01-28 11:58:28 +00:00
|
|
|
private ICollection<string> _logs = new List<string>();
|
|
|
|
|
|
|
|
private bool _shouldRender = false;
|
|
|
|
protected override bool ShouldRender() => _shouldRender;
|
2022-01-17 16:45:52 +00:00
|
|
|
|
2022-01-28 11:58:28 +00:00
|
|
|
private IDisposable? _disposable;
|
|
|
|
|
|
|
|
protected override Task OnInitializedAsync()
|
2022-01-28 10:29:38 +00:00
|
|
|
{
|
|
|
|
_loggerTarget = LogManager.Configuration.FindTargetByName<UiLoggerTarget>("ui");
|
|
|
|
|
2022-01-28 11:58:28 +00:00
|
|
|
_disposable = _loggerTarget.Logs.Sample(TimeSpan.FromMilliseconds(250)).Subscribe(next =>
|
2022-01-28 10:29:38 +00:00
|
|
|
{
|
2022-01-28 11:58:28 +00:00
|
|
|
_logs.Add(next);
|
2022-01-28 10:29:38 +00:00
|
|
|
InvokeAsync(StateHasChanged);
|
|
|
|
});
|
2022-01-28 11:58:28 +00:00
|
|
|
|
|
|
|
_shouldRender = true;
|
|
|
|
return Task.CompletedTask;
|
2022-01-17 16:45:52 +00:00
|
|
|
}
|
2022-01-28 11:58:28 +00:00
|
|
|
|
|
|
|
public void Dispose() => _disposable?.Dispose();
|
2022-01-17 16:45:52 +00:00
|
|
|
}
|