Exemplo n.º 1
0
        public void Add(string message, string message2 = null, long?elapsedMilliseconds = null)
        {
            DateTime now      = DateTime.Now;
            DateTime?duration = null;
            string   msg      = message;

            if (elapsedMilliseconds >= 0)
            {
                duration = (new DateTime(0)).AddMilliseconds((double)elapsedMilliseconds);
                msg      = $"Elapsed time: {duration:HH:mm:ss:fff}. {message}";
            }

            OutputEvent ev = new OutputEvent {
                DateTime = now,
                Message  = string.IsNullOrEmpty(message2) ? message : $"{message}{Environment.NewLine}{message2}",
                Duration = duration
            };

            try {
                if (_control != null)
                {
                    _control.Caption = msg;
                }

                using (StreamWriter sw = File.AppendText(AppInfo.LogFileName)) {
                    sw.WriteLine($"{now:HH:mm:ss.fff} - {msg}");
                    if (!string.IsNullOrEmpty(message2))
                    {
                        sw.WriteLine(message2);
                    }
                }
            }
            catch { }
        }
Exemplo n.º 2
0
        public void Add(string message, string message2 = null, long?elapsedMilliseconds = null)
        {
            DateTime now      = DateTime.Now;
            DateTime?duration = null;
            string   msg      = message;

            if (elapsedMilliseconds >= 0)
            {
                duration = (new DateTime(0)).AddMilliseconds((double)elapsedMilliseconds);
                msg      = $"Elapsed time: {duration:HH:mm:ss:fff}. {message}";
            }

            OutputEvent ev = new OutputEvent {
                DateTime = now,
                Message  = string.IsNullOrEmpty(message2) ? message : $"{message}\n{message2}",
                Duration = duration
            };

            _events.Add(ev);

            try {
                if (_control != null)
                {
                    _control.Caption = msg;
                }

                if (_secondaryControl != null)
                {
                    GridView grid = (GridView)_secondaryControl.MainView;
                    grid.RefreshData();
                }

                using (StreamWriter sw = File.AppendText(Settings.LogFileName)) {
                    sw.WriteLine($"[ {now:HH:mm:ss.fff} ] {msg}");
                    if (!string.IsNullOrEmpty(message2))
                    {
                        sw.WriteLine(message2);
                    }
                }
            }
            catch { }
        }