3
I need to implement Error Log in my application ASP.NET MVC, My question is the following, is there any way I could trigger a method (This would be a method that would save the error log, send the email and related the treatment of Exception) whenever a Exception anywhere in my code not necessarily this being inside a block of Try catch. Example:
//Este método fica na "Escuta" a espera de que ocorra uma exception em qualquer parte do código
public void Exception_Listener(Exception ex){
//Grava o log de erro
GravarLogErro(ex);
}
The idea of this is that I use the call of the method Gravarlogerro() in only one part of the application, and not in all my Blocks of Try Catch, because if I implement one more parameter in this method I would have to turn all the Try Catch of the application to be able to inform the parameter.
I hope you understand me. Thank you very much.
From what I understand Cvoce has the option to configure this in Global.asax eou Web.config, and get the errors via Exception ex = Server.Getlasterror(); see this post in stackoverflow: http://stackoverflow.com/questions/343014/asp-net-custom-error-page-server-getlasterror-is-null
– Junior Porfirio
@Edenilson I also always had this doubt when creating my solutions for logs. And I use Web Forms. So if anyone can give an answer considering the Web Forms.
– Diego Moreno
@Diegomoreno see this link, It teaches the same various application types will suit you: https://msdn.microsoft.com/en-us/library/bb397417.aspx
– Edenilson Bila