/// <summary> /// This method handles writing messages to the system EventLog /// </summary> /// <param name="sentryTask">The task trying to write an event log entry</param> /// <param name="message">The text of the message itself</param> /// <param name="messageType">The message type from the Message Type enumeration</param> private void WriteEventLogEntry(FruitCalculator.Program.TJCApplications application, string message, MessageType messageType) { EventLogEntryType elMessageType = GetMessageTypeForEventLog(messageType); string eventLogMessage = application.ToString() + ": " + message; try { m_eventLog.WriteEntry(eventLogMessage, elMessageType, m_eventId++); } catch (Exception) { // Eat the error. No need to core the app for logging } }
/// This method handles writing messages to the system EventLog /// </summary> /// <param name="sentryTask">The task trying to write an event log entry</param> /// <param name="message">The text of the message itself</param> /// <param name="messageType">The message type from the Message Type enumeration</param> private void WriteConsoleLogEntry(FruitCalculator.Program.TJCApplications application, string message, MessageType messageType) { EventLogEntryType elMessageType = GetMessageTypeForEventLog(messageType); string eventLogMessage = application.ToString() + ": " + message; try { Console.WriteLine(application + ": " + messageType + ": " + message + "."); } catch (Exception) { // Eat the error. No need to core the app for logging Console.WriteLine("An error occurred in writing the error to the console. The error was: " + message + " Error type was: " + messageType); } }
/// <summary> /// This method is what the application can call to log a message /// </summary> /// <param name="sentryTask">The task trying to write a log entry</param> /// <param name="message">The text of the message itself</param> /// <param name="messageType">The message type from the Message Type enumeration</param> public void WriteEntry(FruitCalculator.Program.TJCApplications application, string message, MessageType messageType) { try { // Bail if verbosity is turned off in the app.config file and the message type is INFO bool verbose = GetCustomApplicationLoggerVerbositySetting(); if ((verbose == false) && (messageType == MessageType.Info)) { return; } switch (m_logType) { case LogType.Console: WriteConsoleLogEntry(application, message, messageType); break; //case LogType.Database: // WriteDatabaseLogEntry(application, message, messageType); // break; case LogType.EventViewer: WriteEventLogEntry(application, message, messageType); break; case LogType.All: WriteEventLogEntry(application, message, messageType); WriteConsoleLogEntry(application, message, messageType); break; default: WriteConsoleLogEntry(application, message, messageType); break; } } catch (Exception) { // Eat the error. No need to core the app for logging } }