private void WriteThread() { try { Dictionary <string, StringBuilder> aRecords = new Dictionary <string, StringBuilder>(); StringBuilder aClarify = new StringBuilder(); while (true) { LogTask aLogTask; while (_LogQueue.TryDequeue(out aLogTask)) { try { if (aLogTask.Log != null) { if (!aRecords.ContainsKey(aLogTask.FileName)) { aRecords.Add(aLogTask.FileName, new StringBuilder()); } aRecords[aLogTask.FileName].Append(aLogTask.Log); } if (aLogTask.Clarify != null) { aClarify.Append(aLogTask.Clarify); } } catch (Exception ex) { Trace.WriteLine(ex.Message); } } foreach (var aLog in aRecords) { if (aLog.Value.Length > 0) { try { File.AppendAllText(aLog.Key, aLog.Value.ToString(), Encoding.Unicode); } catch (Exception ex) { Trace.WriteLine(ex.Message); } aLog.Value.Length = 0; } } if (aClarify.Length > 0) { try { ClarifyLog?.Invoke(aClarify.ToString()); } catch (Exception ex) { Trace.WriteLine(ex.Message); } aClarify.Length = 0; } } } catch (ThreadAbortException) { Thread.ResetAbort(); } catch (Exception ex) { Trace.WriteLine(ex.Message); } }
private void RaiseClarifyLog(string aLog) { ClarifyLog?.Invoke(aLog); }