using System.Collections.ObjectModel; using System.ComponentModel; using System.Runtime.CompilerServices; using System.Windows; namespace TeamsNetphoneLink.WPF.MVVM { public class LogEntry { public DateTime Time { get; set; } public string Subsystem { get; set; } public string Type { get; set; } public string Message { get; set; } } public class LogViewModel : INotifyPropertyChanged { // Collection to hold log entries public ObservableCollection LogEntries { get; } = new ObservableCollection(); // Add a log entry public void AddLogEntry(string entry) { Application.Current.Dispatcher.InvokeAsync(() => { LogEntries.Add(new LogEntry { Time = DateTime.Now, Type = "Info", Subsystem = "NONE", Message = entry }); }); } // Add a log entry public void AddLogEntry(string subsystem, string entry) { Application.Current.Dispatcher.InvokeAsync(() => { LogEntries.Add(new LogEntry { Time = DateTime.Now, Type = "Info", Subsystem = subsystem, Message = entry }); }); } // Add a log entry public void AddLogEntry(string type, string subsystem, string entry) { Application.Current.Dispatcher.InvokeAsync(() => { LogEntries.Add(new LogEntry { Time = DateTime.Now, Type = type, Subsystem = subsystem, Message = entry }); }); } public void AddLogEntry(DateTime time, string subsystem, string message) { Application.Current.Dispatcher.InvokeAsync(() => { LogEntries.Add(new LogEntry { Time = time, Type = "Info", Subsystem = subsystem, Message = message }); }); } // Clear all log entries public void ClearLogEntries() { Application.Current.Dispatcher.InvokeAsync(() => { LogEntries.Clear(); }); } // Implement INotifyPropertyChanged public event PropertyChangedEventHandler PropertyChanged; protected void OnPropertyChanged([CallerMemberName] string propertyName = null) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } } }