/// <summary>
        /// Sends a log request via email.
        /// </summary>
        /// <remarks>
        /// Actual email 'Send' calls are commented out.
        /// Uncomment if you have the proper email privileges.
        /// </remarks>
        /// <param name="sender">Sender of the log request.</param>
        /// <param name="e">Parameters of the log request.</param>
        public void Log(object sender, LogEventArgs e)
        {
            string message = "[" + e.Date.ToString() + "] " +
               e.SeverityString + ": " + e.Message;

            // Commented out for now. You need privileges to send email.
            // _smtpClient.Send(_from, _to, _subject, body);
        }
예제 #2
0
 /// <summary>
 /// Write a log request to a file.
 /// </summary>
 /// <param name="sender">Sender of the log request.</param>
 /// <param name="e">Parameters of the log request.</param>
 public void Log(object sender, LogEventArgs e)
 {
     string message = "[" + e.Date.ToString() + "] " +
         e.SeverityString + ": " + e.Message;
     if (e.Exception != null)
     {
         LogController.WriteLog(e.Exception);
     }
     else
     {
         LogController.WriteLog(e.Message);
     }
 }
        /// <summary>
        /// Write a log request to the event log.
        /// </summary>
        /// <remarks>
        /// Actual event log write entry statements are commented out.
        /// Uncomment if you have the proper privileges.
        /// </remarks>
        /// <param name="sender">Sender of the log request.</param>
        /// <param name="e">Parameters of the log request.</param>
        public void Log(object sender, LogEventArgs e)
        {
            string message = "[" + e.Date.ToString() + "] " +
                e.SeverityString + ": " + e.Message;

            var eventLog = new EventLog();
            eventLog.Source = "Patterns In Action";

            // Map severity level to an Windows EventLog entry type
            var type = EventLogEntryType.Error; 
            if (e.Severity < LogSeverity.Warning) type = EventLogEntryType.Information;
            if (e.Severity < LogSeverity.Error) type = EventLogEntryType.Warning;

            // In try catch. You will need proper privileges to write to eventlog.
            try { eventLog.WriteEntry(message, type); }
            catch { /* do nothing */ }
        }
예제 #4
0
 /// <summary>
 /// Invoke the Log event.
 /// </summary>
 /// <param name="e">Log event parameters.</param>
 public void OnLog(LogEventArgs e)
 {
     if (Log != null)
     {
         Log(this, e);
     }
 }