コード例 #1
0
        /// <summary>
        /// The handling of the notification event.
        /// </summary>
        protected virtual void Notifications_NotificationEvent(object sender, EventNotification notification)
        {
            if (LogFileName.IsNullOrEmptyTrimmed())
            return;

              StringBuilder sb = new StringBuilder();
              if (OutputType == LoggingManagerFileOutputTypeOption.Text)
              {
            sb.AppendFormat("{0} {1}: {2} ", DateTime.Now.ToShortDateString(), DateTime.Now.ToLongTimeString(), notification.Level);
            if (sender != null)
              sb.AppendFormat(sender.GetType().FullName);

            sb.AppendLine();
            foreach (EventMessage message in notification.Messages)
            {
              if (message.IsNewLine)
            sb.AppendLine();

              sb.Append(message.Message);
            }
            sb.AppendLine();
            sb.AppendLine();
              }
              else
              {
            sb.AppendLine("<tr style=\"border:1px;\">");
            sb.AppendFormat("<td style=\"border-top:1px solid #333;\">{0} {1}</td>", DateTime.Now.ToShortDateString(), DateTime.Now.ToLongTimeString());
            sb.AppendLine();
            sb.AppendLine("<td style=\"border-top:1px solid #333;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>");
            sb.AppendFormat("<td style=\"border-top:1px solid #333;\"><Font color=\"{0}\"><b>{1}</b></font></td>",
              Notifications.GetHtmlColor(notification.Level, EventColor.EventDefault), notification.Level);
            sb.AppendLine();
            sb.AppendLine("<td style=\"border-top:1px solid #333;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>");

            if (sender != null)
              sb.AppendFormat("<td style=\"border-top:1px solid #333;\">{0}</td>", sender.GetType().FullName);
            else
              sb.AppendFormat("<td style=\"border-top:1px solid #333;\">&nbsp;</td>");

            sb.AppendLine("<td style=\"border-top:1px solid #333;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>");
            sb.AppendFormat("<td style=\"border-top:1px solid #333;\">");
            foreach (EventMessage message in notification.Messages)
            {
              if (message.IsNewLine)
            sb.AppendLine("<br />");

              if (message.Color == EventColor.Default)
            sb.AppendFormat("<Font color=\"Black\">");
              else
            sb.AppendFormat("<Font color=\"{0}\">", Notifications.GetHtmlColor(notification.Level, message.Color));

              sb.Append(message.Message.Replace("\r\n", "<br />"));
              sb.Append("</font>");
            }
            sb.AppendLine("</td>");
            sb.AppendLine("</tr>");
              }

              SaveToLogFile(sb.ToString());
        }
コード例 #2
0
 /// <summary>
 /// Fires a warning event for notification of actions.
 /// </summary>
 /// <param name="sender">The sender of the event.</param>
 /// <param name="addExtraSpace">Should there be extra space around this notification?</param>
 /// <param name="messages">The messages to notify users about.</param>
 public static void FireWarningEvent(object sender, bool addExtraSpace, params EventMessage[] messages)
 {
     try
       {
     EventNotification notification = new EventNotification(EventLevel.Warning, addExtraSpace);
     notification.Messages.AddRange(messages);
     FireEvent(sender, notification);
       }
       catch (Exception e)
       {
     TechnolutionExceptionStack te = new TechnolutionExceptionStack(e);
     te.LogParameterValue(sender, "sender");
     te.LogParameterValue(addExtraSpace, "addExtraSpace");
     te.LogParameterValue(messages, "messages");
     throw te.GetStackToThrow();
       }
 }
コード例 #3
0
        /// <summary>
        /// Fires a critical event for notification of actions.
        /// </summary>
        /// <param name="sender">The sender of the event.</param>
        /// <param name="technolutionException">The exception to notify users about.</param>
        public static void FireExceptionEvent(object sender, TechnolutionExceptionStack technolutionException)
        {
            EventNotification notification = new EventNotification(EventLevel.Critical, false);
              notification.Messages.Add(new EventMessage("Exception Occurred: {0}", technolutionException.ToString()));

              if (ExceptionEvent != null)
            ExceptionEvent.Invoke(technolutionException);

              FireEvent(sender, notification, true);
        }
コード例 #4
0
        /// <summary>
        /// Fires a trace event for notification of actions.
        /// </summary>
        /// <param name="sender">The sender of the event.</param>
        /// <param name="addExtraSpace">Should there be extra space around this notification?</param>
        /// <param name="messages">The messages to notify users about.</param>
        public static void FireTraceEvent(object sender, bool addExtraSpace, params EventMessage[] messages)
        {
            try
              {
            if (sender == null)
              return;

            if ((sender is Type) && (!CheckTraceNamespace((Type)sender)))
              return;

            if ((!(sender is Type)) && (!CheckTraceNamespace(sender.GetType())))
              return;

            EventNotification notification = new EventNotification(EventLevel.Trace, addExtraSpace);
            notification.Messages.AddRange(messages);
            FireEvent(sender, notification);
              }
              catch (Exception e)
              {
            TechnolutionExceptionStack te = new TechnolutionExceptionStack(e);
            te.LogParameterValue(sender, "sender");
            te.LogParameterValue(addExtraSpace, "addExtraSpace");
            te.LogParameterValue(messages, "messages");
            throw te.GetStackToThrow();
              }
        }
コード例 #5
0
        /// <summary>
        /// Fires an event for notification of actions.
        /// </summary>
        /// <param name="sender">The sender of the event.</param>
        /// <param name="notification">The notification to send.</param>
        /// <param name="loggingOnly">Only send this to the logging listener.</param>
        public static void FireEvent(object sender, EventNotification notification, bool loggingOnly = false)
        {
            if (sender is string)
            throw new InvalidCodeException("Fire Notification Event called without Sender Object.");

              if (sender is EventMessage)
            throw new InvalidCodeException("Fire Notification Event called without Sender Object.");

              try
              {
            if (CheckLoggingLevel(notification.Level))
            {
              if (LoggingEvent != null)
              {
            notification.SetParameterMessages();
            LoggingEvent.Invoke(sender, notification);
              }
            }

            if ((CheckDisplayLevel(notification.Level)) && (!loggingOnly))
            {
              if (DisplayEvent != null)
              {
            notification.SetParameterMessages();
            DisplayEvent.Invoke(sender, notification);
              }
            }
              }
              catch (Exception e)
              {
            TechnolutionExceptionStack te = new TechnolutionExceptionStack(e);
            te.LogParameterValue(sender, "sender");
            te.LogParameterValue(notification, "notification");
            throw te.GetStackToThrow();
              }
        }