private static void WriteToDebugFile(TEXT_LOG_EVENT log) { if (System.Threading.Thread.CurrentThread.Name != null && System.Threading.Thread.CurrentThread.Name.Contains("TracePro")) { return; } if (_logFile == null) { try { _logFile = System.IO.File.CreateText(System.IO.Path.Join(GlobalConfig.GetSettingPath(CONSTANTS.PathKey.TraceSaveDirectory), "DebugLog.txt")); _logFile.WriteLine($"Opened new rgat debug logfile at {DateTime.Now.ToLocalTime().ToLongDateString()}"); _logFile.WriteLine($"Uncheck bulk logging in settings->misc to disable this"); } catch (Exception e) { Logging.RecordError($"Bulk log file cannot be created ({e}). Ensure Trace Save Directory is writable."); GlobalConfig.Settings.Logs.BulkLogging = false; } } if (_logFile != null) { _logFile.WriteLine($"{System.Threading.Thread.CurrentThread.Name}:{log.Trace?.PID}:{log.Graph?.ThreadID}:{log.Text}"); _logFile.Flush(); } }
/// <summary> /// Display a message in the logfile/message window. /// Will also be shown on the UI alert pane with the Alert/Error options /// </summary> /// <param name="text">Message to display</param> /// <param name="filter">The LogFilterType category of the log entry /// </param> /// <param name="graph">Graph this applies to. If aimed at a trace, just use any graph of the trace</param> /// <param name="trace">Process this applies to</param> public static void RecordLogEvent(string text, LogFilterType filter = LogFilterType.Info, ProtoGraph?graph = null, TraceRecord?trace = null) { TEXT_LOG_EVENT log = new TEXT_LOG_EVENT(filter: filter, text: text); if (graph != null) { log.SetAssociatedGraph(graph); } if (trace != null) { log.SetAssociatedTrace(trace); } lock (_messagesLock) { //write all logs to the logfile in bulk logging mode if (GlobalConfig.Settings.Logs.BulkLogging) { try { WriteToDebugFile(log); } catch (Exception e) { GlobalConfig.Settings.Logs.BulkLogging = false; Logging.RecordLogEvent($"Error: Not able to write to bulk log file {e.Message}. Another rgat may be using it. Disabling bulk logging."); } } //write non-bulklog files to the UI log pane if (filter != LogFilterType.BulkDebugLogFile) { _logMessages.Add(log); if (log.Filter == LogFilterType.Alert || log.Filter == LogFilterType.Error) { UnseenAlerts += 1; _alertNotifications.Add(log); _lastAlert = DateTime.Now; } MessageCounts[(int)filter] += 1; } } //todo remove after debug done if (filter == LogFilterType.Error) { WriteConsole(text, ConsoleColor.Yellow); } }