I am trying to configure Logback to send emails whenever an exception (Logging level: ERROR) occurs. I have not been able to make it work so far so I would like to ask for y
You have to enable Marker based triggering of email.
include an evaluator in your logback.xml under SMTP appender refer below link
http://logback.qos.ch/manual/appenders.html#OnMarkerEvaluator
then add below logic in your Exception catch block,pass Marker object to logger method if you want to send email like below -
Marker notifyAdmin = MarkerFactory.getMarker("NOTIFY_ADMIN");
logger.error(notifyAdmin,
"This is a serious an error requiring the admin's attention",
new Except
ion("Just testing"));
its possible that in some scenario you dont want to send email and only want to log the exception then just dont pass Marker object to logger method.
logger.error("This is a serious an error requiring the admin's attention",
new Except
ion("Just testing"));