3
Answers

How to create error log in MVC 5

I have created a project in MVC5, I want to create an error log for same.
 
is there any way that we can get detailed information about the error. 
 
as of now, i am catching exception like below. 
 
catch (Exception Ex)
{
mailobj.SendMail(
this.ControllerContext.RouteData.Values["controller"].ToString(),
this.ControllerContext.RouteData.Values["action"].ToString(),
Convert.ToString(Ex.Message.Replace("<", "").Replace(">", "").ToString()),
Convert.ToString(Ex.HelpLink),
Convert.ToString(Ex.Source),
Convert.ToString(Ex.StackTrace),
Convert.ToString(Ex.TargetSite));
return Json("error in the system.!", JsonRequestBehavior.AllowGet);
}
 
hear send mail will send mail to admin about error.
 
but the problem is, I could not able to get complete details about the error for example, if you get error message like "Object reference not set to an instance of an object." I want to to what is the parameter value to get this data.
 
Is there any easy way that we can track the errors in the system.
  
 
 
 
Answers (3)
1
Satheesh Elumalai

Satheesh Elumalai

NA 1.3k 148.9k 7y
Jut refer this site 
https://stackoverflow.com/questions/23053875/event-and-error-logging-in-asp-net-mvc-5-project 
0
Vivek Kumar

Vivek Kumar

NA 7.6k 729.8k 7y
Have a look into the below links.
 
http://blog.chudinov.net/errors-handling-and-logging-in-asp-net-mvc/
 
http://www.c-sharpcorner.com/blogs/sample-logging-using-nlog
 
https://www.codeproject.com/Tips/1003107/Error-logging-in-MVC-and-WebAPI-using-ELMAH
 
https://dusted.codes/demystifying-aspnet-mvc-5-error-pages-and-error-logging
 
 http://www.dotnetcurry.com/aspnet-mvc/1260/exception-handling-logging-aspnet-mvc
0
Thiruppathi R

Thiruppathi R

NA 8.7k 371.3k 7y
This URl may useful for you
https://dusted.codes/demystifying-aspnet-mvc-5-error-pages-and-error-logging