mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
Fix logger support
This commit is contained in:
parent
13f3557e7b
commit
fa79f10a18
@ -30,6 +30,7 @@ namespace Wabbajack
|
||||
|
||||
public App()
|
||||
{
|
||||
RxApp.MainThreadScheduler = new DispatcherScheduler(Dispatcher.CurrentDispatcher);
|
||||
_host = Host.CreateDefaultBuilder(Array.Empty<string>())
|
||||
.ConfigureLogging(AddLogging)
|
||||
.ConfigureServices((host, services) =>
|
||||
@ -57,10 +58,10 @@ namespace Wabbajack
|
||||
|
||||
var consoleTarget = new ConsoleTarget("console");
|
||||
|
||||
var uiTarget = new LogStream()
|
||||
var uiTarget = new LogStream
|
||||
{
|
||||
Name = "ui",
|
||||
Layout = "${message}",
|
||||
Layout = "${message:withexception=false}",
|
||||
};
|
||||
|
||||
loggingBuilder.Services.AddSingleton(uiTarget);
|
||||
@ -76,8 +77,6 @@ namespace Wabbajack
|
||||
|
||||
private static IServiceCollection ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
RxApp.MainThreadScheduler = new DispatcherScheduler(Dispatcher.CurrentDispatcher);
|
||||
|
||||
services.AddOSIntegrated();
|
||||
|
||||
services.AddSingleton<CefService>();
|
||||
|
@ -1,7 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Reactive.Disposables;
|
||||
using System.Reactive.Subjects;
|
||||
using System.Text;
|
||||
using System.Windows.Data;
|
||||
using DynamicData;
|
||||
using DynamicData.Binding;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using NLog;
|
||||
using NLog.Targets;
|
||||
@ -12,11 +16,40 @@ namespace Wabbajack.Models;
|
||||
public class LogStream : TargetWithLayout
|
||||
{
|
||||
|
||||
public readonly SourceCache<ILogMessage, long> MessageLog = new(x => x.MessageId);
|
||||
private readonly SourceCache<ILogMessage, long> _messageLog = new(x => x.MessageId);
|
||||
private readonly Subject<ILogMessage> _messages = new();
|
||||
|
||||
public readonly ReadOnlyObservableCollection<ILogMessage> _messagesFiltered;
|
||||
private readonly CompositeDisposable _disposables;
|
||||
public ReadOnlyObservableCollection<ILogMessage> MessageLog => _messagesFiltered;
|
||||
public IObservable<ILogMessage> Messages => _messages;
|
||||
|
||||
|
||||
public LogStream()
|
||||
{
|
||||
_disposables = new CompositeDisposable();
|
||||
_messageLog.Connect()
|
||||
.Bind(out _messagesFiltered)
|
||||
.Subscribe()
|
||||
.DisposeWith(_disposables);
|
||||
|
||||
Messages
|
||||
.ObserveOnGuiThread()
|
||||
.Subscribe(m => _messageLog.AddOrUpdate(m))
|
||||
.DisposeWith(_disposables);
|
||||
|
||||
_messages.DisposeWith(_disposables);
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
_disposables.Dispose();
|
||||
}
|
||||
|
||||
protected override void Write(LogEventInfo logEvent)
|
||||
{
|
||||
MessageLog.AddOrUpdate(new LogMessage(logEvent));
|
||||
_messages.OnNext(new LogMessage(logEvent));
|
||||
}
|
||||
public interface ILogMessage
|
||||
{
|
||||
@ -30,7 +63,7 @@ public class LogStream : TargetWithLayout
|
||||
private record LogMessage(LogEventInfo info) : ILogMessage
|
||||
{
|
||||
public long MessageId => info.SequenceID;
|
||||
public string ShortMessage => info.ToString();
|
||||
public string ShortMessage => info.FormattedMessage;
|
||||
public DateTime TimeStamp => info.TimeStamp;
|
||||
public string LongMessage => info.FormattedMessage;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user