示例#1
0
        /// <summary>
        /// Выполнить запись ошибки в жкрнал событий
        /// </summary>
        /// <param name="sender">Источник сообщения</param>
        /// <param name="args">Параметры сообщения</param>
        public static void WriteToLog(object sender, ErrorArgs args)
        {
            try
            {
                if (journal != null)
                {
                    switch (args.ErrorType)
                    {
                        case ErrorType.Information:

                            journal.Write(args.Message, EventLogEntryType.Information);
                            break;

                        case ErrorType.Warning:

                            journal.Write(args.Message, EventLogEntryType.Warning);
                            break;

                        case ErrorType.NotFatal:

                            journal.Write(args.Message, EventLogEntryType.Error);
                            break;

                        case ErrorType.Fatal:

                            journal.Write(args.Message, EventLogEntryType.Error);
                            if (OnExit != null)
                            {
                                OnExit(sender, new EventArgs());
                            }
                            break;

                        case ErrorType.Unknown:

                            journal.Write(args.Message, EventLogEntryType.Error);
                            break;

                        case ErrorType.Default:

                            journal.Write(args.Message, EventLogEntryType.Information);
                            break;
                    }
                }
                else
                {
                    journal = Journal.CreateInstance();
                    if (journal != null)
                    {
                        string message = string.Format("{0}{1}{2}", "Не был создан экземпляр класса Journal",
                            Constants.vbCrLf, "Сообщение приложения будет сохранено как Error!");

                        journal.Write(message, EventLogEntryType.Error);
                        journal.Write(args.Message, EventLogEntryType.Error);
                    }
                }
            }
            catch
            {
                // ...
            }
        }
示例#2
0
        /// <summary>
        /// Выполнить запись ошибки в жкрнал событий
        /// </summary>
        /// <param name="sender">Источник сообщения</param>
        /// <param name="args">Параметры сообщения</param>
        public static void WriteToLog(object sender, ErrorArgs args)
        {
            try
            {
                if (journal != null)
                {
                    switch (args.ErrorType)
                    {
                    case ErrorType.Information:

                        journal.Write(args.Message, EventLogEntryType.Information);
                        break;

                    case ErrorType.Warning:

                        journal.Write(args.Message, EventLogEntryType.Warning);
                        break;

                    case ErrorType.NotFatal:

                        journal.Write(args.Message, EventLogEntryType.Error);
                        break;

                    case ErrorType.Fatal:

                        journal.Write(args.Message, EventLogEntryType.Error);
                        if (OnExit != null)
                        {
                            OnExit(sender, new EventArgs());
                        }
                        break;

                    case ErrorType.Unknown:

                        journal.Write(args.Message, EventLogEntryType.Error);
                        break;

                    case ErrorType.Default:

                        journal.Write(args.Message, EventLogEntryType.Information);
                        break;
                    }
                }
                else
                {
                    journal = Journal.CreateInstance();
                    if (journal != null)
                    {
                        string message = string.Format("{0}{1}{2}", "Не был создан экземпляр класса Journal",
                                                       Constants.vbCrLf, "Сообщение приложения будет сохранено как Error!");

                        journal.Write(message, EventLogEntryType.Error);
                        journal.Write(args.Message, EventLogEntryType.Error);
                    }
                }
            }
            catch
            {
                // ...
            }
        }