コード例 #1
0
 private static void OnMessageServiceMessageSent(object sender, MessageEventArgs e)
 {
     switch (e.Status)
     {
         case MessageStatus.Success:
             Log(string.Format("Send of message \"{0}\" completed - remaining messages: {1}",
             e.Message, e.QueuedMessageCount), ConsoleColor.Red);
             break;
         case MessageStatus.Failure:
             Log(string.Format("Send failed" + Environment.NewLine +
             "Reason: {0}", e.Error), ConsoleColor.Red);
             break;
     }
 }
コード例 #2
0
 private void Log(MessageEventArgs e)
 {
     string message;
     LogCategory category;
     switch (e.Status)
     {
         case MessageStatus.Success:
             message = string.Format("Send of message \"{0}\" completed - remaining messages: {1}",
             e.Message, e.QueuedMessageCount);
             category = LogCategory.Message;
             break;
         case MessageStatus.Failure:
             message = string.Format("Send failed" + Environment.NewLine +
             "Reason: {0}", e.Error);
             category = LogCategory.Message;
             break;
         case MessageStatus.Connecting:
             message = "Trying to connect";
             category = LogCategory.Connection;
             break;
         default:
             message = e.Message;
             category = LogCategory.Connection;
             break;
     }
     LogMessage msg = new LogMessage(DateTime.Now, message, category);
     string formattedMessage = msg.FormattedMessage;
     File.AppendAllText(_logpath, formattedMessage, Encoding.UTF8);
     //forward to eventlistener
     if (MessageSent != null && category == LogCategory.Message)
     {
         MessageSent(this, e);
     }
 }