mirror of
https://git.teknik.io/Teknikode/Teknik.git
synced 2023-08-02 14:16:22 +02:00
Added email notification on exceptions.
This commit is contained in:
parent
76e887cba0
commit
6e8eb52966
@ -1,6 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Mail;
|
||||
using System.Text;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Teknik.Areas.Error.ViewModels;
|
||||
@ -24,6 +26,11 @@ namespace Teknik.Areas.Error.Controllers
|
||||
Response.TrySkipIisCustomErrors = true;
|
||||
}
|
||||
|
||||
if (exception != null)
|
||||
{
|
||||
SendErrorEmail(exception);
|
||||
}
|
||||
|
||||
ErrorViewModel model = new ErrorViewModel();
|
||||
model.Exception = exception;
|
||||
|
||||
@ -43,6 +50,11 @@ namespace Teknik.Areas.Error.Controllers
|
||||
Response.TrySkipIisCustomErrors = true;
|
||||
}
|
||||
|
||||
if (exception != null)
|
||||
{
|
||||
SendErrorEmail(exception);
|
||||
}
|
||||
|
||||
ErrorViewModel model = new ErrorViewModel();
|
||||
model.Description = exception.Message;
|
||||
model.Exception = exception;
|
||||
@ -62,6 +74,11 @@ namespace Teknik.Areas.Error.Controllers
|
||||
Response.TrySkipIisCustomErrors = true;
|
||||
}
|
||||
|
||||
if (exception != null)
|
||||
{
|
||||
SendErrorEmail(exception);
|
||||
}
|
||||
|
||||
ErrorViewModel model = new ErrorViewModel();
|
||||
model.Exception = exception;
|
||||
|
||||
@ -99,10 +116,45 @@ namespace Teknik.Areas.Error.Controllers
|
||||
Response.TrySkipIisCustomErrors = true;
|
||||
}
|
||||
|
||||
if (exception != null)
|
||||
{
|
||||
SendErrorEmail(exception);
|
||||
}
|
||||
|
||||
ErrorViewModel model = new ErrorViewModel();
|
||||
model.Exception = exception;
|
||||
|
||||
return View("/Areas/Error/Views/Error/Http500.cshtml", model);
|
||||
}
|
||||
|
||||
private void SendErrorEmail(Exception ex)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Let's also email the message to support
|
||||
SmtpClient client = new SmtpClient();
|
||||
client.Host = Config.ContactConfig.Host;
|
||||
client.Port = Config.ContactConfig.Port;
|
||||
client.EnableSsl = Config.ContactConfig.SSL;
|
||||
client.DeliveryMethod = SmtpDeliveryMethod.Network;
|
||||
client.UseDefaultCredentials = true;
|
||||
client.Credentials = new System.Net.NetworkCredential(Config.ContactConfig.Username, Config.ContactConfig.Password);
|
||||
client.Timeout = 5000;
|
||||
|
||||
MailMessage mail = new MailMessage(Config.SupportEmail, Config.SupportEmail);
|
||||
mail.Subject = string.Format("Exception Occured on: {0}", Request.Url.AbsoluteUri);
|
||||
mail.Body = string.Format(@"
|
||||
Message: {0}
|
||||
|
||||
Source: {1}
|
||||
|
||||
Stack Trace: {2}", ex.Message, ex.Source, ex.StackTrace);
|
||||
mail.BodyEncoding = UTF8Encoding.UTF8;
|
||||
mail.DeliveryNotificationOptions = DeliveryNotificationOptions.Never;
|
||||
|
||||
client.Send(mail);
|
||||
}
|
||||
catch (Exception) { /* don't handle something in the handler */ }
|
||||
}
|
||||
}
|
||||
}
|
@ -108,8 +108,10 @@ namespace Teknik
|
||||
|
||||
protected void Application_Error(object sender, EventArgs e)
|
||||
{
|
||||
// Get the last exception
|
||||
Exception exception = Server.GetLastError();
|
||||
|
||||
|
||||
// Clear the response
|
||||
Response.Clear();
|
||||
|
||||
HttpException httpException = exception as HttpException;
|
||||
|
Loading…
Reference in New Issue
Block a user