Esempio n. 1
0
        public void PostMessage(string msg, LogCategory c)
        {
            if (!MyLogWindow.LoggingEnabled)
            {
                return;
            }

            var l = new LogMessageVM()
            {
                Text     = msg,
                Category = c,
                DateTime = DateTime.Now
            };

            Messages.Add(l);

            MyMessageTextBlock.Text = msg.
                                      Replace("\n", " ").
                                      Replace("\t", " ").
                                      Replace("\r", " ");
            CurrentIcon          = l.Image;
            MyTimeTextBlock.Text = l.DateTime.ToLongTimeString();

            MyLogWindow.WriteToLog(l);
        }
Esempio n. 2
0
        internal void OpenLogFile()
        {
            if (Program.LogToFile && LoggingEnabled)
            {
                using (MyLogFileStream = File.Open(LogFilePath, FileMode.OpenOrCreate, FileAccess.Read, FileShare.Read))
                    using (var reader = new StreamReader(MyLogFileStream))
                    {
                        while (!reader.EndOfStream)
                        {
                            string l = reader.ReadLine();

                            if (string.IsNullOrWhiteSpace(l))
                            {
                                continue;
                            }

                            string[] p = l.Split('|');

                            if (p.Length != 3)
                            {
                                continue;
                            }

                            var m = new LogMessageVM();
                            for (int i = 0; i <= 2; ++i)
                            {
                                string x = p[i].Trim();
                                if (i == 0)
                                {
                                    m.DateTime = DateTime.Parse(x);
                                }
                                else if (i == 1)
                                {
                                    m.Category = Utils.StrToEnum <LogCategory>(x);
                                }
                                else if (i == 2)
                                {
                                    m.Text = x;
                                }
                            }
                            Messages.Add(m);
                        }

                        reader.Close();
                    }

                MyLogFileStream       = File.Open(LogFilePath, FileMode.Append, FileAccess.Write, FileShare.Read);
                MyLogFileStreamWriter = new StreamWriter(MyLogFileStream);
            }
        }