Beispiel #1
0
        /// <summary>
        /// Takes an exception and, if logging is enabled, logs it to the database
        /// </summary>
        /// <param name="ex">The exception object</param>
        /// <param name="messageType">The type of message being logged</param>
        /// <param name="messageSeverity">The severity of the message being logged</param>
        public static void LogException(Exception ex, MessageTypeEnum messageType, MessageSeverityEnum messageSeverity)
        {
            try
            {
                String details = FormatExceptionForLog(ex);

                LogMessage(ex.Message, details, messageType, messageSeverity);
            }
            catch             // Never let logging crash the site!
            {
                return;
            }
        }
Beispiel #2
0
            /// <summary>Запись сообщения.</summary>
            /// <param name="x_lImportanceLevel">уровень важности сообщения.</param>
            /// <param name="x_sSource">имя источника сообщения.</param>
            /// <param name="x_ulType">тип сообщения.</param>
            /// <param name="x_ulForm">вид сообщения.</param>>
            /// <param name="x_sCategory">категория сообщения.</param>
            /// <param name="x_sDescription">текст сообщения.</param>
            /// <returns>True, если при  записи сообщения не возникли ошибки.</returns>
            public bool WriteMessage(
                MessageSeverityEnum x_lImportanceLevel,
                string x_sSource,
                MessageTypeEnum x_ulType,
                MessageFormEnum x_ulForm,
                string x_sCategory,
                string x_sDescription)
            {
                bool c_bSucceeded = false;

                // Проверка необходимости записи отладочного сообщения.
                if ((x_ulForm == MessageFormEnum.RELEASE_MESSAGE) ||
                    ((m_lJournalMode == JournalModeEnum.DEBUG_ON) && (x_ulForm == MessageFormEnum.DEBUG_MESSAGE)))
                {
                    // Проверка важности сообщения.
                    if (x_lImportanceLevel >= m_lSeverityLevel)
                    {
                        // Проверка необходимости использования взаимного исключения при записи сообщения.
                        if (String.IsNullOrEmpty(m_sMutexName))
                        {
                            // Вызов записи сообщения, переопределяемого в классе-потомке.
                            c_bSucceeded = WritingMessage(x_sSource, x_ulType, x_ulForm, x_sCategory, x_sDescription);
                        }
                        else
                        {
                            bool c_bCaptured = false;
                            // Запрос владения журналом сообщений.
                            Mutex c_mxLockJournal = new Mutex(true, m_sMutexName, out c_bCaptured);

                            if (!c_bCaptured)
                            {
                                // Ожидание освобождения журнала сообщений.
                                c_mxLockJournal.WaitOne();
                            }
                            try {
                                // Вызов записи сообщения, переопределяемого в классе-потомке.
                                c_bSucceeded = WritingMessage(x_sSource, x_ulType, x_ulForm, x_sCategory, x_sDescription);
                            }
                            finally {
                                // Освобождение журнала сообщений.
                                c_mxLockJournal.ReleaseMutex();
                            }
                        }
                    }
                }

                return(c_bSucceeded);
            }
Beispiel #3
0
 /// <summary>Создание объекта.</summary>
 public CJournal()
 {
     // Чтение значений параметров журнала, сохраненных в файле конфигурации.
     try {
         // Чтение допустимого уровеня важности сообщения.
         m_lSeverityLevel = (MessageSeverityEnum)Enum.Parse(
             typeof(MessageSeverityEnum),
             ConfigurationManager.AppSettings[GetType().FullName + "." + n_sSettings_SeverityLevel]);
     }
     catch {
         // Использование значения по умолчанию.
         m_lSeverityLevel = MessageSeverityEnum.LOW_PRIORITY;
     }
     try {
         // Чтение режима работы журнала сообщений.
         m_lJournalMode = (JournalModeEnum)Enum.Parse(
             typeof(JournalModeEnum),
             ConfigurationManager.AppSettings[GetType().FullName + "." + n_sSettings_JournalMode]);
     }
     catch {
         // Использование значения по умолчанию.
         m_lJournalMode = JournalModeEnum.DEBUG_OFF;
     }
 }
Beispiel #4
0
        /// <summary>
        /// Takes a message or alert, and if logging is enabled, logs it to the database
        /// For logging exceptions, SysLog.LogException should be used to capture the details of the exception
        /// </summary>
        /// <param name="message">A general description of the message being logged</param>
        /// <param name="details">Detailed information about the message</param>
        /// <param name="messageType">The type of message being logged</param>
        /// <param name="messageSeverity">The severity of the message being logged</param>
        public static void LogMessage(string message, string details, MessageTypeEnum messageType, MessageSeverityEnum messageSeverity)
        {
            try
            {
                if (!AppLogic.AppConfigBool("System.LoggingEnabled"))
                {
                    return;
                }

                if (!CommonLogic.StringInCommaDelimitedStringList("database", AppLogic.AppConfig("System.LoggingLocation")))
                {
                    return;
                }

                new SysLog
                {
                    Message         = System.Web.HttpUtility.HtmlEncode(Security.ScrubCCNumbers(message)),
                    Details         = System.Web.HttpUtility.HtmlEncode(Security.ScrubCCNumbers(details)),
                    MessageType     = messageType,
                    MessageSeverity = messageSeverity
                }.Commit();
            }
            catch             // Never let logging crash the site!
            {
                return;
            }
        }
Beispiel #5
0
        /// <summary>
        /// Takes a message or alert, and if logging is enabled, logs it to the database
        /// For logging exceptions, SysLog.LogException should be used to capture the details of the exception
        /// </summary>
        /// <param name="message">A general description of the message being logged</param>
        /// <param name="details">Detailed information about the message</param>
        /// <param name="messageType">The type of message being logged</param>
        /// <param name="messageSeverity">The severity of the message being logged</param>
        public static void LogMessage(string message, string details, MessageTypeEnum messageType, MessageSeverityEnum messageSeverity)
        {
            try // Never let logging crash the site!
            {
                string loggingLocation = AppLogic.AppConfig("System.LoggingLocation");
                bool   loggingEnabled  = AppLogic.AppConfigBool("System.LoggingEnabled");

                if (loggingEnabled && CommonLogic.StringInCommaDelimitedStringList("database", loggingLocation))
                {
                    SysLog logEntry = new SysLog();

                    logEntry.Message         = Security.HtmlEncode(Security.ScrubCCNumbers(message));
                    logEntry.Details         = Security.HtmlEncode(Security.ScrubCCNumbers(details));
                    logEntry.MessageType     = messageType;
                    logEntry.MessageSeverity = messageSeverity;

                    logEntry.Commit();
                }
                else
                {
                    return;
                }
            }
            catch
            {
                return;
            }
        }