mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
Update Logging Target
This commit is contained in:
parent
a725688495
commit
2fab1b462f
@ -40,12 +40,13 @@ public partial class App
|
||||
Layout = "${processtime} [${level:uppercase=true}] (${logger}) ${message:withexception=true}",
|
||||
Header = "############ Wabbajack log file - ${longdate} ############"
|
||||
};
|
||||
|
||||
var consoleTarget = new ConsoleTarget("console");
|
||||
var uiTarget = new MemoryTarget
|
||||
|
||||
var uiTarget = new UiLoggerTarget
|
||||
{
|
||||
Name = "ui",
|
||||
Layout = "${message}",
|
||||
|
||||
};
|
||||
|
||||
var blackholeTarget = new NullTarget("blackhole");
|
||||
|
@ -1,23 +1,32 @@
|
||||
@using NLog
|
||||
@using NLog.Targets
|
||||
@using Wabbajack.App.Blazor.Utility
|
||||
@using System.Reactive.Linq
|
||||
@namespace Wabbajack.App.Blazor.Components
|
||||
|
||||
<div id="virtual-logger">
|
||||
<Virtualize Items="@Logs" Context="logItem" OverscanCount="3">
|
||||
<span @key="logItem">@logItem</span>
|
||||
</Virtualize>
|
||||
@foreach (var logItem in _logs)
|
||||
{
|
||||
<span>@logItem</span>
|
||||
}
|
||||
</div>
|
||||
|
||||
@code {
|
||||
|
||||
// TODO: [Low] More parameters to customise the logger. E.g. Reverse order.
|
||||
// TODO: [High] Find a way to auto-scroll. (JS interop?)
|
||||
|
||||
private MemoryTarget? _memoryTarget;
|
||||
private ICollection<string> Logs => _memoryTarget?.Logs ?? Array.Empty<string>();
|
||||
private UiLoggerTarget? _loggerTarget;
|
||||
private ICollection<string> _logs = Array.Empty<string>();
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
_memoryTarget = LogManager.Configuration.FindTargetByName<MemoryTarget>("ui");
|
||||
_loggerTarget = LogManager.Configuration.FindTargetByName<UiLoggerTarget>("ui");
|
||||
|
||||
// TODO: can do different things here, buffering is just the simples operation
|
||||
_loggerTarget.Logs.Buffer(TimeSpan.FromSeconds(1)).Subscribe(next =>
|
||||
{
|
||||
_logs = next;
|
||||
InvokeAsync(StateHasChanged);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
17
Wabbajack.App.Blazor/Utility/UILoggerTarget.cs
Normal file
17
Wabbajack.App.Blazor/Utility/UILoggerTarget.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Reactive.Subjects;
|
||||
using NLog;
|
||||
using NLog.Targets;
|
||||
|
||||
namespace Wabbajack.App.Blazor.Utility;
|
||||
|
||||
public class UiLoggerTarget : TargetWithLayout
|
||||
{
|
||||
private readonly Subject<string> _logs = new();
|
||||
public IObservable<string> Logs => _logs;
|
||||
|
||||
protected override void Write(LogEventInfo logEvent)
|
||||
{
|
||||
_logs.OnNext(RenderLogEvent(Layout, logEvent));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user