Last post May 02, 2018 12:50 PM by Khuram.Shahzad
Apr 29, 2018 01:30 PM|murali krishna14|LINK
I have an existing project, it is in asp.net web forms
in that project every event (page_load,button_click,dropdown_selectionIndexChanged etc.....) is calling in between try catch block like below
protected void Page_Load(object sender, EventArgs e)
catch (Exception ex)
ShowMessage(ex.Message + "<br />" + ex.StackTrace, 1);
in existing project we are just showing exception message to the users.
Now i want to log all exception messages in a log file( i can able to write log files)
but in my project we have many number of web pages and every page having many events, so for logging each and every catch block in all events is to much time consuming and i need to write the log code in all catch blocks in all pages.
so is there any option to globally write log message for all try catch events in all pages.
it would be more helpful to me
Apr 29, 2018 02:35 PM|DA924|LINK
You can create a base class that all aspx.cs codebehind classes inherit from the base class.
You can catch any exception globally.
You can use Log4Net that can be installed using Nuget to log the exception.
May 01, 2018 06:38 AM|Nan Yu|LINK
Since you are able to write log file , the global place to handle uncatched Exceptions could be in Global.asax by handling Application_Error :
For .NET framework, the most popular logging libraries are probably log4net and NLog. You can consider using that libraries.
May 02, 2018 12:50 PM|Khuram.Shahzad|LINK
Here you will find different solutions, I hope catching event at global level will help you, you need to throw error up from pages