When
customErrors mode ="Off"
, it shows custom error page and save exception in the log file.When
customErrors mode ="On"
, it shows custom error page but does not create any log file.
What is the issue?
Code:
protected void Application_Error(object sender, EventArgs e)
{
Exception filterContext = Server.GetLastError();
//Server.ClearError();
StringBuilder builder = new StringBuilder();
builder
.AppendLine("start")
.AppendLine(DateTime.Now.ToString()+filterContext.Source)
SendMail("****@gmail.com", "Error Details", builder.ToString());
string filePath = Server.MapPath("~/App_Data/Error_" +
DateTime.Now.ToString("dd_MM_yyyy") + ".log");
using (StreamWriter writer = System.IO.File.AppendText(filePath))
{
writer.Write(builder.ToString());
writer.Flush();
}
}
and my custom error page
public ActionResult NotFound()
{
return View();
}
public ActionResult Error()
{
return View();
}
how to store log into text file