using CommunityToolkit.Mvvm.ComponentModel; using log4net; using Microsoft.IdentityModel.Logging; using Polly; using System; using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Documents; using Admin.Core.Tasks; namespace Aucma.Core.SheetMetal.ViewModels { public class LogPageViewModel : ObservableObject { private ObservableCollection listItems = new ObservableCollection(); private static readonly log4net.ILog log = LogManager.GetLogger(typeof(LogPageViewModel)); public LogPageViewModel() { Job_Admin_Quartz.LogDelegateEvent += PrintMessageToListBox; } /// /// LisBox数据模板 /// private IEnumerable logInfoListBox; public IEnumerable LogInfoListBox { get => logInfoListBox; set => SetProperty(ref logInfoListBox, value); } /// /// listBox绑定日志 /// /// private void PrintMessageToListBox(string message) { try { listItems.Add($"{DateTime.Now.ToString("HH:mm:ss")}==>{message}"); LogInfoListBox = listItems.OrderByDescending(x => x); } catch (Exception ex) { log.Error("日志数据绑定异常", ex); } } } }