Today i am showing you the coolest way to logging ASP.NET mvc login with ELMAH. I am using visual studio 2013
1.Lets Create a Project Name ElmahMvc
2.Install nuget package nuget
Install-Package Elmah.MVC
3. Raise an Exception .There you go access error log by your local url/elmah
http://localhost:20351/elmah
The saving database and Emailing is bit of configuration to take ….
Lets look at it
1.Download ELMAH script form official site
2.add a database named log and run the script
3.add a connection string in web.config
1 2 3 |
<connectionStrings> <add name="elmah" connectionString="Data Source=.;Initial Catalog=log;Persist Security Info=True;User ID=sa;Password=pass" providerName="System.Data.SqlClient" /> </connectionStrings> |
4.Add a elmah element in web.config
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
<elmah> <errorLog type="Elmah.SqlErrorLog, Elmah" connectionStringName="elmah" /> <!--For Addtional Mail Config .Remove it if not need for mail on every error--> <errorMail from="waltoncrm@waltonbd.com" to="mrahman.cse32@waltonbd.com" subject="Application Exception" async="false" smtpPort="25" smtpServer="YourServer" userName="uName" password="pass"> </errorMail> </elmah> |
and mail additional under System.WebServer
1 2 3 4 5 6 7 |
<system.net> <mailSettings> <smtp deliveryMethod ="Network"> <network host="smtp.gmail.com" port="587" userName="yourgmailEmailAddress" password="yourGmailEmailPassword" /> </smtp> </mailSettings> </system.net> |
Download my sample project and Elmah script with Visual Studio 2013
Download ELMAH MVC
Note:if you donot want to crash your program or use it in asp.net web form Static [WebMethod]
This seems perfect
1 2 3 4 5 6 7 8 |
try { //some web method code } catch(Exception ex) { Elmah.ErrorSignal.FromCurrentContext().Raise(ex); } |
If you find any problem ,please leave a comment