@using NLog
@using NLog.Targets
@using Wabbajack.App.Blazor.Utility
@using System.Reactive.Linq
@namespace Wabbajack.App.Blazor.Components
@implements IDisposable
@logItem
@code {
// TODO: [Low] More parameters to customise the logger. E.g. Reverse order.
// TODO: [High] Find a way to auto-scroll. (JS interop?)
private UiLoggerTarget? _loggerTarget;
private ICollection _logs = new List();
private bool _shouldRender = false;
protected override bool ShouldRender() => _shouldRender;
private IDisposable? _disposable;
protected override Task OnInitializedAsync()
{
_loggerTarget = LogManager.Configuration.FindTargetByName("ui");
_disposable = _loggerTarget.Logs.Sample(TimeSpan.FromMilliseconds(250)).Subscribe(next =>
{
_logs.Add(next);
InvokeAsync(StateHasChanged);
});
_shouldRender = true;
return Task.CompletedTask;
}
public void Dispose() => _disposable?.Dispose();
}