Skip to main content

ASP .Net MVC Error Logging Using Elmah


What is ELMAH?

ELMAH stand for Error logging Modules and Handlers. ELMAH is one of the popular Library to logging unhandled errors provided by Google. .It’s an application wide error logging facility which can be dynamically plugged.
For More Info ELMAH

Advantage:-
·         You can log almost all unhandled exceptions in the system.
·         An email notification of each error occurs.
·         You can insert log a various locations like files text file, SQL Server, Oracle etc.

In this blog I am explaining how to use Elmah in MVC application.

Step 1:-ELMAH NuGet Package:
There is a nuget package also available for ELMAH. You can find at following link.
http://www.nuget.org/packages/elmah.mvc/
and Following Command you have to run for installing NuGet Pacakge.
Install-Package Elmah.Mvc

Step 2:- Now open web config file and add the following code inside <system.web> 
    < httpHandlers > 
    < add verb = "POST,GET,HEAD"path = "elmah.axd"type = "Elmah.ErrorLogPageFactory, Elmah" / > 
    < /httpHandlers> 
  
Also, add the following code inside <system.webServer>
    < handlers > 
    < add name = "Elmah"verb = "POST,GET,HEAD"path = "elmah.axd"type = "Elmah.ErrorLogPageFactory, Elmah" / > 
    < /handlers> 

Step 3:- Build solution and Run. if you go to http://yoursite.com/<PageName>.For example http://localhost:51873/Cart.Here Cart page is not exits. So it gives error 404 page not found.




Step 4:- Then go to http://yoursite.com/elmah. Then it gives error of that page not fount with date and time. Look at that below.


Download Code Here...
  
Hope you like it. Stay tuned for more..

Comments

Popular posts from this blog

What is typescript & Its features ?

Define Typescript:- TypeScript (TS) is an open source programming language developed by Microsoft. Typescript is a superset of JavaScript which primarily provides optional static typing, classes and interfaces. What is the different static and dynamic typing? Static typing:- It's all about the variables. In statically typed program languages, if I create an integer, I have to tell the compiler that it is an integer and will always be an integer. Dynamic typing:- In dynamic languages, you don't specify the type and you can dynamically change the type. For example, to declare a variable in Javascript, you would type var bar; . If I then set it to an integer, it will work fine. bar = 5; . I can then even later set the same variable to a string, bar = "Hello World!"; and it will work fine! Hence the term dynamic. Before we start typescript lets show some ECMAScript 6 Features that help in typescript. 1.          ...

What is the difference between ViewData and ViewBag?

1:-ViewData ViewData is a dictionary of objects that is derived from ViewDataDictionary class and accessible using strings as keys.  ViewData requires typecasting for complex data type and check for null values to avoid error Example:- public ActionResult Index() {        ViewData["Name"] = "Dhiren Web developer";       return View(); } 2:-ViewBag ViewBag is a dynamic property that takes advantage of the new dynamic features in C# 4.0.  ViewBag doesn’t require typecasting for complex data type. Example:-   public ActionResult Index()   {      ViewBag.Name = "Dhiren Web developer";      return View();    } Calling in View @ViewBag.Name @ViewData["Name"] Hope you like it. Stay tuned for more..

Understanding ASP.NET MVC Folder Structure

Following Structure of Solution Explorer  Visual Stdio 2015 display in image: Explain in Short: App_Data folder - Holds the SQL Server Compact database file. Content - Holds CSS files. Controllers - Holds controller classes. DAL folder - The data access layer.  Holds the context, initializer, repository, and unit of work classes. Logging folder - Holds code that does logging. Migrations folder - Holds EF Code First migrations code, including the Seed method. Models folder - Holds model classes. Properties or MyProject folder - Project properties. Scripts folder - Script files. ViewModels folder - Holds view model classes. Views folder - Holds view classes. Visual Studio project file (.csproj or .vbproj). Packages.config - Specifies NuGet packages included in the project. Global.asax file - Includes database initializer code. Web.config file - Includes the connection string to the database. Hope you like it. Stay...