Files

59 lines
1.7 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NLog;
using Prism.Events;
using Prism.Regions;
using RIZO_Application.Core;
using RIZO_Application.Core.Mvvm;
namespace RIZO_Application.Modules.Base.ViewModels
{
public class SystemLogViewModel : RegionViewModelBase
{
private readonly IEventAggregator _eventAggregator;
private SubscriptionToken _token;
private string _logMessage = "";
private Logger _logger = LogManager.GetCurrentClassLogger();
public string LogMessage
{
get { return _logMessage; }
set { SetProperty(ref _logMessage, value); }
}
public SystemLogViewModel(
IRegionManager regionManager,
IEventAggregator eventAggregator)
: base(regionManager)
{
OnLogReceived("初始化日志系统");
_eventAggregator = eventAggregator;
// 订阅事件使用UI线程处理保持强引用
_token = _eventAggregator.GetEvent<SystemLogEvent>().Subscribe(OnLogReceived, ThreadOption.UIThread, true);
}
private void OnLogReceived(string message)
{
Debug.WriteLine(message);
LogMessage += $"\n{DateTime.Now}: {message}";
_logger.Info($"\n{DateTime.Now}: {message}");
}
public void Destroy()
{
_token?.Dispose();
}
public void AddTestLogMessage()
{
}
public override void OnNavigatedTo(NavigationContext navigationContext)
{
//do something
}
}
}