updated NLog to v5
fixed most of issues with world creating/loading fixed log window lags fixed some compiler warnings fixed empty log files creating fixed logging performance added better logging of load process commands autocomplete in torch GUI chat in torch GUI now has entered history (like console, use up/down arrows) abstraction of instance manager session name now correctly displaying in torchSessionManager messages TorchSession now has loaded world property (as torch now has more control about world load process) now only dedicated config locks after session start
This commit is contained in:
51
Torch.Server/LogViewerTarget.cs
Normal file
51
Torch.Server/LogViewerTarget.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Threading;
|
||||
using NLog;
|
||||
using NLog.Targets;
|
||||
using Torch.Server.ViewModels;
|
||||
using Torch.Server.Views;
|
||||
|
||||
namespace Torch.Server
|
||||
{
|
||||
/// <summary>
|
||||
/// NLog target that writes to a <see cref="LogViewerControl"/>.
|
||||
/// </summary>
|
||||
[Target("logViewer")]
|
||||
public sealed class LogViewerTarget : TargetWithLayout
|
||||
{
|
||||
public IList<LogEntry> LogEntries { get; set; }
|
||||
public SynchronizationContext TargetContext { get; set; }
|
||||
private readonly int _maxLines = 1000;
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Write(LogEventInfo logEvent)
|
||||
{
|
||||
TargetContext?.Post(_sendOrPostCallback, logEvent);
|
||||
}
|
||||
|
||||
private void WriteCallback(object state)
|
||||
{
|
||||
var logEvent = (LogEventInfo) state;
|
||||
LogEntries?.Add(new(logEvent.TimeStamp, Layout.Render(logEvent), LogLevelColors[logEvent.Level]));
|
||||
}
|
||||
|
||||
private static readonly Dictionary<LogLevel, SolidColorBrush> LogLevelColors = new()
|
||||
{
|
||||
[LogLevel.Trace] = new SolidColorBrush(Colors.DimGray),
|
||||
[LogLevel.Debug] = new SolidColorBrush(Colors.DarkGray),
|
||||
[LogLevel.Info] = new SolidColorBrush(Colors.White),
|
||||
[LogLevel.Warn] = new SolidColorBrush(Colors.Magenta),
|
||||
[LogLevel.Error] = new SolidColorBrush(Colors.Yellow),
|
||||
[LogLevel.Fatal] = new SolidColorBrush(Colors.Red),
|
||||
};
|
||||
|
||||
private readonly SendOrPostCallback _sendOrPostCallback;
|
||||
|
||||
public LogViewerTarget()
|
||||
{
|
||||
_sendOrPostCallback = WriteCallback;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user