public void Log(string Message, string FileName, MessageBoxIcon WarrningLevel, string StackInfo) { if (InvokeRequired) { // We're not in the UI thread, so we need to call BeginInvoke Invoke(new LogDelegate(Log), new object[] { Message, FileName, WarrningLevel, StackInfo }); return; } //from forms thread DateTime date = DateTime.Now; string TimeString = date.ToString("H:mm:ss.fff"); string LogFileName; //to file try { LogFileName = Path.GetDirectoryName(Properties.Settings.Default.Out_dbfile) + Path.DirectorySeparatorChar + "Isotrack.log"; } catch (Exception) { // для кэширования сырых нет нормального меcта для лога LogFileName = Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + "Isotrack.log"; } StreamWriter sw = new StreamWriter(LogFileName, true); string FileMessage = "Info:"; if (WarrningLevel == MessageBoxIcon.Warning) { FileMessage = "Warning!"; } if (WarrningLevel == MessageBoxIcon.Error) { FileMessage = "ERROR!"; } FileMessage += "\t" + TimeString; FileMessage += "\t" + Message; if (StackInfo != null) { FileMessage += "\n StackInfo:" + StackInfo; } sw.WriteLine(FileMessage); sw.Close(); //to form ListViewItem LItem = new ListViewItem(); LItem.Text = TimeString; LItem.SubItems.Add(FileName); LItem.SubItems.Add(Message); if (StackInfo != null) { LItem.SubItems.Add(StackInfo); } LItem.ToolTipText = LItem.Text; if (WarrningLevel == MessageBoxIcon.Warning) { LItem.BackColor = Color.Yellow; } if (WarrningLevel == MessageBoxIcon.Error) { LItem.BackColor = Color.Red; } LogList.Items.Add(LItem); LogList.EnsureVisible(LogList.Items.Count - 1); Application.DoEvents(); }