Search code examples
c#asp.net-coreserilog

Serilog send mail if exception is thrown in specific assembly


I'm working on a asp.net core (2.2) app that contains multiple assemblies. For logging I use serilog for asp.net core. Now there's a requirement to send a mail when an exception is thrown. The crux is: The email shall only be sent if the exception is thrown in one specific assembly. Is there a way to achieve this with the serilog email sink? Thank you.


Solution

  • It's not specific to the email sink, but any logger configuration. See this answer for quite a few examples. Classes and namespaces can be filtered as well, and you could have exceptions from other assemblies get logged via a different sink. like rolling file. Filter Serilog logs to different sinks depending on context source?