You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Aucma.Scada/Aucma.Scada.UI/viewModel/LogInfoViewModel.cs

52 lines
1.4 KiB
C#

1 year ago
using GalaSoft.MvvmLight;
using HighWayIot.Log4net;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Aucma.Scada.UI.viewModel
{
public class LogInfoViewModel : ViewModelBase
{
private LogHelper logHelper = LogHelper.Instance;
private IEnumerable listBoxData;
/// <summary>
/// LisBox数据模板
/// </summary>
public IEnumerable ListBoxData
{
get { return listBoxData; }
set { listBoxData = value; RaisePropertyChanged(() => ListBoxData); }
}
private ObservableCollection<dynamic> listItems = new ObservableCollection<dynamic>();
public LogInfoViewModel()
{
PrintMessageToListBox("打印日志");
}
/// <summary>
/// listBox绑定日志
/// </summary>
/// <param name="message"></param>
private void PrintMessageToListBox(string message)
{
try
{
listItems.Add($"{DateTime.Now.ToString("HH:mm:ss")}==>{message}");
ListBoxData = listItems.OrderByDescending(x => x);
}catch(Exception ex)
{
logHelper.Error("日志数据绑定异常", ex);
}
}
}
}