Hi Guys in this post i will show you, how you can log javascipt erros in your asp.net mvc applications.
First of all, let me tell you the tools.
1. Visual Studio 2013
2. ASP.NET MVC 4
4. Elmah.mvc
5. Jsnlog.elmah
6. SQL Server 2008
So we can start
1. Create an MVC application.
2. Got to Nugget and add Elmah.MVC, Please note i using elmah’s mvc package
3. Now go to elmah site and download sql scripts for elmah
4. Create a database named Logging and apply the downloaded script.
5. Go to web.config and add connection string for elmah
6.Configure elmah in web.config by adding this
<elmah> <errorLog type="Elmah.SqlErrorLog, Elmah" connectionStringName="elmah" /> <security allowRemoteAccess="false" /> </elmah>
7. Great now thorw an exception from your home controller
8. Go to elmah, if you saw this screen, we are good, elmah is configured correctly
9. Again back to Nugget and add Jsnlog for elmah
10. Go to your _Layout.csftml and add this at top
@Html.Raw(JSNLog.JavascriptLogging.Configure()) <script type="text/javascript"> window.onerror = function (errorMsg, url, lineNumber, column, errorObj) { // Send object with all data to server side log, using severity fatal, // from logger "onerrorLogger" JL("onerrorLogger").fatalException({ "msg": "Exception!", "errorMsg": errorMsg, "url": url, "line number": lineNumber, "column": column }, errorObj); // Tell browser to run its own error handler as well return false; } </script>
11. Make some javascript error in index.cshtml
@section scripts{ <script type="text/javascript"> JL().info("This is a log message"); xyz; </script> }
You must be logged in to post a comment.