ExceptionSenderMiddleware
watches for unhandled exceptions. When found - details are saved to text files in specific folder.
ExceptionSenderTask
monitors that folder and sends exception info to you by email (using MailGun.com, but you can add your own)
Written for ASP.NET Core (ASP.NET 5, ASP.NET vNext) projects.
- Exception message and stacktrace are captured;
- Last N log records captured (Logging.Memory is used);
- Captured data saved in
logs
subdirectory for later processing; - Task (based on RecurrentTasks) is used for checking new exception data;
- Every single exception - one email to you;
- MailGun is used to send emails (free quota 10K emails/month), you can add new mail providers (inherit from
ExceptionSenderTask
); - When new exception is caught - tries to send immediately;
- When message sucessfully sent - files are deleted from disk;
- Can send message to multiple recipients (multiple
To
)
Use NuGet package Logging.ExceptionSender
If you wish to use MailGun
for sending mail, you need to create account (or use existing one, if any).
Register your site at MailGun.com and write down your domain name and api key:
Sample (minimum) configuration in config.json
(aka appsettings.json
):
{
...
"ExceptionSender": {
"MailgunBaseUrl": "https://api.mailgun.net/v3/", // some accounts need https://api.eu.mailgun.net/v3/
"MailgunDomain": "example.com",
"MailgunApiKey": "key-*************",
"From": "[email protected]",
"To": ["[email protected]", "[email protected]"]
}
...
}
In ConfigureServices
method of your Startup.cs
:
services.AddMailgunExceptionSender(Configuration.GetSection("ExceptionSender"));
In Configure
method of your Statup.cs
:
// Enable in-memory logging
loggerFactory.AddMemory();
// Activate ExceptionSender middleware to catch ASP exceptions
app.UseExceptionSender();