Change logging while sending sync
authorThomas
Tue, 26 Nov 2019 09:04:14 +0100
branchsync
changeset 2884e76145dc3bcf
parent 2883 f8123d159059
child 2885 82201f5798ae
Change logging while sending
AdapterCallbacks.cs
     1.1 --- a/AdapterCallbacks.cs	Mon Nov 25 11:02:45 2019 +0100
     1.2 +++ b/AdapterCallbacks.cs	Tue Nov 26 09:04:14 2019 +0100
     1.3 @@ -5,6 +5,7 @@
     1.4  using System;
     1.5  using System.Diagnostics;
     1.6  using System.Runtime.InteropServices;
     1.7 +using System.Threading.Tasks;
     1.8  
     1.9  namespace pEp
    1.10  {
    1.11 @@ -126,22 +127,35 @@
    1.12              }
    1.13  
    1.14              // Try to log the message
    1.15 -            try
    1.16 +            if (newMessage.IsSecure)
    1.17              {
    1.18 -                if (newMessage.IsSecure)
    1.19 +                try
    1.20                  {
    1.21                      new MsgProcessor().Decrypt(newMessage, out PEPMessage decryptedMessage);
    1.22                      string xml = ThisAddIn.PEPEngine.PERToXERSyncMessage(decryptedMessage.ToCOMType());
    1.23                      Log.Verbose("MessageToSend: Starting to send message from " + msg.From.Address + ": " + Environment.NewLine + Environment.NewLine + xml);
    1.24                  }
    1.25 -                else
    1.26 +                catch (Exception ex)
    1.27                  {
    1.28 -                    Log.Verbose("MessageToSend: Sending beacon from " + msg.From.Address);
    1.29 +                    Log.Error("MessageToSend: Error logging message content. " + ex.ToString());
    1.30                  }
    1.31              }
    1.32 -            catch (Exception ex)
    1.33 +            else
    1.34              {
    1.35 -                Log.Error("MessageToSend: Error logging message content. " + ex.ToString());
    1.36 +                // For beacons, use task to prevent race condition during startup of engine
    1.37 +                TextMessage m = msg;
    1.38 +                Task.Run(() =>
    1.39 +                {
    1.40 +                    try
    1.41 +                    {
    1.42 +                        string xml = ThisAddIn.PEPEngine.PERToXERSyncMessage(m);
    1.43 +                        Log.Verbose("MessageToSend: Starting to send message from " + m.From.Address + ": " + Environment.NewLine + Environment.NewLine + xml);
    1.44 +                    }
    1.45 +                    catch (Exception ex)
    1.46 +                    {
    1.47 +                        Log.Error("MessageToSend: Error logging message content. " + ex.ToString());
    1.48 +                    }
    1.49 +                });
    1.50              }
    1.51  
    1.52              // Now send the message