using Serilog; using Serilog.Core; using Serilog.Events; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; namespace SafeBagDE70.Admin { /// /// Interaction logic for LogViewerUC.xaml /// public partial class LogViewerUC : UserControl { private ObservableCollection _logItems = new ObservableCollection(); public LogViewerUC(ObservableCollection logCollection) { InitializeComponent(); LogListBox.ItemsSource = logCollection; } private void LogInfoButton_Click(object sender, RoutedEventArgs e) { Log.Information("This is an informational log message"); } } public class RealTimeLogSink : ILogEventSink { private readonly IFormatProvider _formatProvider; private readonly ObservableCollection _logCollection; public RealTimeLogSink(ObservableCollection logCollection, IFormatProvider formatProvider = null) { _logCollection = logCollection; _formatProvider = formatProvider; } public void Emit(LogEvent logEvent) { var message = logEvent.RenderMessage(_formatProvider); var logLevel = logEvent.Level.ToString(); var timestampedMessage = $"[{logEvent.Timestamp:HH:mm:ss}] [{logLevel}]{message}"; // Ensure the message is added on the UI thread App.Current.Dispatcher.Invoke(() => _logCollection.Add(timestampedMessage)); } } }