Logger.cs (1237B)
1 using System; 2 using System.Collections.ObjectModel; 3 using System.IO; 4 using System.IO.IsolatedStorage; 5 using System.Threading.Tasks; 6 using System.Windows; 7 using Windows.Storage; 8 using System.Text; 9 using Windows.Storage.Streams; 10 using System.Windows.Threading; 11 12 namespace WinPhoneFtp.FtpService 13 { 14 public sealed class Logger 15 { 16 private static Logger s_Logger = null; 17 public static Logger GetDefault(Dispatcher UIDispatcher) 18 { 19 if (s_Logger == null) 20 { 21 s_Logger = new Logger(UIDispatcher); 22 } 23 return s_Logger; 24 } 25 26 private Dispatcher UIDispatcher = null; 27 28 private Logger(Dispatcher UIDispatcher) 29 { 30 Logs = new ObservableCollection<String>(); 31 this.UIDispatcher = UIDispatcher != null ? UIDispatcher : Deployment.Current.Dispatcher; 32 } 33 34 public ObservableCollection<String> Logs 35 { 36 get; 37 private set; 38 } 39 40 public void AddLog(String LogInfo) 41 { 42 UIDispatcher.BeginInvoke(() => 43 { 44 System.Diagnostics.Debug.WriteLine(LogInfo); 45 Logs.Add(LogInfo); 46 }); 47 } 48 } 49 }