I am working on configuring NLog
configuration which works perfectly for logging into text files. Now on the top of this I want to set a conditional target as Mail
which should get fired only for a specific set of exceptions. For example - if there is a PaymentFailedException
, CardExpiredException
then the NLog
should target Mail
. I have checked the NLog
documentation but I could not find any way to set it for specific set of exceptions. However, NLog
allows for setting target as Mail
for exception levels.
You could configure use the <when>
for this.
eg
<logger name="*" writeTo="myMailTarget">
<filters>
<when condition="not contains('${exception:format=type}', 'PaymentFailedException") action="Ignore" />
</filters>
</logger>
See filtering log messages and <when>
docs
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.