Beispiel #1
0
        private static bool TryWriteToMemory(DebugLogItem item)
        {
            try
            {
                DebugLog.LogItems.Add(item);
                return(true);
            }
            catch (Exception ex)
            {
                // Write some debug output to help troubleshoot this
                System.Diagnostics.Debug.WriteLine(
                    "Exception at TryWriteDebugLogToMemory: " +
                    ex.Message);

                return(false);
            }
        }
Beispiel #2
0
        internal static void WriteLogItem(
            DateTime time,
            string source,
            DebugLogType type,
            string title,
            string data)
        {
            // Make this "thread safe"
            lock (BigBadLock)
            {
                try
                {
                    int logid = DebugLog.LogItems.Count;

                    DebugLogItem item = new DebugLogItem(logid, time, source, type, title, data);

                    DebugLog.TryWriteToMemory(item);

                    // If the user wants to save debug output and we haven't disabled, then commit debug logs
                    // to disk as well
                    if (DebugLog.ShouldSaveDebugOutput && DebugLog.DebugLogDiskCommitEnabled)
                    {
                        if (!TryWriteToDisk(item))
                        {
                            // Don't keep trying to write to disk if it fails once
                            DebugLog.DebugLogDiskCommitEnabled = false;
                        }
                    }
                }
                catch (Exception ex)
                {
                    // Write some debug output to help troubleshoot this
                    System.Diagnostics.Debug.WriteLine(
                        "Exception at WriteTraceMessage: \n" +
                        ex.Message);
                }
            }
        }
Beispiel #3
0
        private static bool TryWriteToDisk(DebugLogItem item)
        {
            try
            {
                StringBuilder sb = new StringBuilder();
                sb.Append(item.Time.ToString("s"));
                sb.Append("|");
                sb.Append(item.Type.ToString());
                sb.Append("|");
                sb.Append(item.Source);
                sb.Append("|");
                sb.Append(item.Title);
                sb.Append("|");
                sb.AppendLine();

                if (!String.IsNullOrEmpty(item.Data))
                {
                    sb.Append(item.Data);
                    sb.AppendLine();
                }

                // Write the debug log to the output file
                string LogEntry = sb.ToString();
                System.IO.File.AppendAllText(DebugLog.LogFile, LogEntry);
                return(true);
            }
            catch (Exception ex)
            {
                // Write some debug output to help troubleshoot this
                System.Diagnostics.Debug.WriteLine(
                    "Exception at TryWriteDebugLogToDisk: " +
                    ex.Message);

                return(false);
            }
        }