示例#1
0
        /// <summary>
        /// Logs a message.
        /// </summary>
        /// <param name="priority">A LogFileEntryPriority indicating the priority of the message.</param>
        /// <param name="message">A string containing the message to be logged.</param>
        public static void LogMessage(LogFileEntryPriority priority, string message)
        {
            LogFileEntry Entry;

            GetSourceDetails(out string Component, out string Operation);
            Entry = new LogFileEntry(priority, Component, Operation, message);
            LogFile.WriteEntry(Entry);
        }
示例#2
0
        private static string ParseEntry(LogFileEntry entry)
        {
            string ReturnValue;
            string Timestamp;

            Timestamp   = entry.Timestamp.ToString("yyyy-MM-dd HH-mm-ss.ffff");
            ReturnValue = $"{Timestamp},{entry.Priority},{entry.Component},{entry.Operation},{entry.Message}";

            return(ReturnValue);
        }
示例#3
0
        /// <summary>
        /// Writes the specified entry to the log file.
        /// </summary>
        /// <param name="entry">A LogFileEntry that is the entry to write.</param>
        internal static void WriteEntry(LogFileEntry entry)
        {
            if ((int)entry.Priority <= (int)MaximumPriority)
            {
                // Check for duplicates
                if (!_PreviousMessages.Contains(entry.Message))
                {
                    string Line;

                    _PreviousMessages.Add(entry.Message);
                    Line = ParseEntry(entry);
                    WriteLine(Line);
                }

                while (_PreviousMessages.Count > 5)
                {
                    _PreviousMessages.RemoveAt(0);
                }
            }
        }
示例#4
0
        /// <summary>
        /// Logs an exception.
        /// </summary>
        /// <param name="ex">An Exception that is the exception to log.</param>
        public static void LogException(Exception ex)
        {
            int          Count = 0;
            LogFileEntry Entry;
            Exception    InnerEx;
            string       Message = string.Empty;

            InnerEx = ex;
            while (InnerEx != null)
            {
                string StackTrace = string.Empty;

                Message += $"{Count}: {InnerEx.GetType().FullName}|{InnerEx.Message}||";
                Message += InnerEx.StackTrace.Replace("\r\n", "|");
                Message += "||";
                InnerEx  = InnerEx.InnerException;
                Count++;
            }

            GetSourceDetails(out string Component, out string Operation);
            Entry = new LogFileEntry(LogFileEntryPriority.Error, Component, Operation, Message);
            LogFile.WriteEntry(Entry);
        }