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

56 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 ObservableCollection<dynamic> listItems = new ObservableCollection<dynamic>();
public LogInfoViewModel()
{
PrintMessageToListBox("打印日志");
}
#region 参数定义
1 year ago
private IEnumerable listBoxData;
/// <summary>
/// LisBox数据模板
/// </summary>
public IEnumerable ListBoxData
{
get { return listBoxData; }
set { listBoxData = value; RaisePropertyChanged(() => ListBoxData); }
}
#endregion
1 year ago
/// <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);
}
}
}
}