In case of a system exception (or sessionContext.setRollbackOnly
), the global transaction is rolled back by the container (if you use container managed transactions).
That means that any actions on an XA-aware resource enlisted in the global transaction are rolled back.
This includes in your case the pending message which you want to send to your logger. This one gets deleted, because the transaction is rolled back.
In your case it should be enough, if you use a non XA connection factory. This way the message should be sent at once (in case of a logger even helpful). So sending runs in a local transaction spanning the JMS sending task only.
As for non EJB objects: You could extract your sending functionality using a non XA connection factory into a normal Java class (= not an EJB), and use it both from EJBs and normal classes.