コード例 #1
0
        private SysLogEntry tail;               // Tail of the in-memory log

        /// <summary>
        /// Constructs a logger that logs directly to the IDE debug output.
        /// </summary>
        public DebugSysLogProvider()
            : base()
        {
            this.format   = SysLogEntryFormat.AllButTime;
            this.inMemory = false;
            this.fileName = null;
        }
コード例 #2
0
 /// <summary>
 /// Constructs a logger that caches the log in-memory and flushes
 /// the output to the IDE debug output or a file.
 /// </summary>
 /// <param name="inMemory"><c>true</c> to enable in-memory caching.</param>
 /// <param name="format">The log entry format.</param>
 /// <param name="fileName">
 /// Pass as the file name where log entries are to be appended
 /// when Flush() is called or <c>null</c> to append these thes to the
 /// IDE debug output.
 /// </param>
 public DebugSysLogProvider(bool inMemory, SysLogEntryFormat format, string fileName)
     : base()
 {
     this.format   = format;
     this.inMemory = inMemory;
     this.fileName = fileName;
     this.head     = null;
     this.tail     = null;
 }
コード例 #3
0
        /// <summary>
        /// Renders the log entry into a string.
        /// </summary>
        /// <param name="format">The formatting option flags.</param>
        /// <returns>The formatted string.</returns>
        public string ToString(SysLogEntryFormat format)
        {
            var sb = new StringBuilder();

            if ((format & SysLogEntryFormat.ShowBar) != 0)
            {
                sb.Append("=================================\r\n");
            }

            if ((format & SysLogEntryFormat.ShowTime) != 0)
            {
                sb.AppendFormat((IFormatProvider)null, "Time: {0} UTC\r\n", Time.ToString("MM-dd-yyyy HH:mm:ss.fff"));
            }

            if (this.Message != null)
            {
                sb.Append(Message);
                sb.Append("\r\n");
            }

            if (Extension != null && (format & SysLogEntryFormat.ShowExtended) != 0)
            {
                sb.AppendFormat((IFormatProvider)null, Extension.Format());
            }

            if (this.Exception != null)
            {
                AppendException(sb, this.Exception);
            }
            else if (this.Category != null)
            {
                if ((format & SysLogEntryFormat.ShowType) != 0)
                {
                    sb.AppendFormat((IFormatProvider)null, "{0}: {1}\r\n", Type.ToString(), Category);
                }
                else
                {
                    sb.AppendFormat((IFormatProvider)null, "{0}\r\n", Category);
                }
            }
            else
            {
                if ((format & SysLogEntryFormat.ShowType) != 0)
                {
                    sb.AppendFormat((IFormatProvider)null, "{0}:\r\n", Type.ToString());
                }
            }

            return(sb.ToString());
        }
コード例 #4
0
        //---------------------------------------------------------------------
        // Static members

        /// <summary>
        /// Configures the current application instance with a debug log.
        /// </summary>
        /// <param name="inMemory"><c>true</c> to enable in-memory caching.</param>
        /// <param name="format">Log display format.</param>
        /// <param name="fileName">
        /// Pass as the file name where log entries are to be appended
        /// when Flush() is called or <c>null</c> to append these thes to the
        /// IDE debug output.
        /// </param>
        /// <remarks>
        /// This method will delete any existing log file if present.
        /// </remarks>
        public static void SetDebugLog(bool inMemory, SysLogEntryFormat format, string fileName)
        {
            if (fileName != null)
            {
                try
                {
                    File.Delete(fileName);
                }
                catch
                {
                }
            }

            SysLog.LogProvider = new DebugSysLogProvider(inMemory, format, fileName);
        }