Bill Berlington
Bill Berlington

Reputation: 2414

Send email alerts from Nlog for specific exceptions

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.

Upvotes: 1

Views: 350

Answers (1)

Julian
Julian

Reputation: 36720

You could configure use the <when> for this.

e.g.

<logger name="*" writeTo="myMailTarget">
  <filters>
    <when condition="not contains('${exception:format=type}', 'PaymentFailedException") action="Ignore" />
  </filters>
</logger> 

See filtering log messages and <when> docs

Upvotes: 2

Related Questions