Wednesday, September 3, 2014

Implement Elmah MVC And asp.net

ELMAH (Error logging Modules and Handlers) is framework which handle the log exception in our application .It is pluggable framework and easily can add asp.net website. So you can easily get the ELMAH library from nuget package.
There is a nuget package also available for ELMAH. You can find at following link.

So install the Elmah package from the Package Manager console in Visual Studio
Install-Package elmah

Now    you have to get the following setting in web config file
configuration>
  <configSections>
    <sectionGroup name="elmah">
      <section name="security" requirePermission="false" type="Elmah.SecuritySectionHandler, Elmah" />
      <section name="errorLog" requirePermission="false" type="Elmah.ErrorLogSectionHandler, Elmah" />
      <section name="errorMail" requirePermission="false"type="Elmah.ErrorMailSectionHandler, Elmah" />
     
    </sectionGroup>
  </configSections>
  <system.web>
    <compilation debug="true" strict="false" explicit="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
    <httpModules>
      <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />
      <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" />
     
    </httpModules>

  </system.web>

  <system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <modules>
      <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" preCondition="managedHandler"/>
      <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah"preCondition="managedHandler" />
    
    </modules>
  </system.webServer>
  <elmah>
    <security allowRemoteAccess="true" />
    <errorLog type="Elmah.SqlErrorLog, Elmah" connectionStringName="DefaultConnection" />

    <errorMail from="****" to="****" subject="Error in Application" smtpServer="localhost" smtpPort="25" async="false"    />
   
    <security allowRemoteAccess="false" />
 </elmah>
  <location path="elmah.axd" inheritInChildApplications="false">
    <system.web>
      <httpHandlers>
        <add verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah"/>
      </httpHandlers>
     
      
       
         
      

      -->
    </system.web>
    <system.webServer>
      <handlers>
        <add name="ELMAH" verb="POST,GET,HEAD" path="elmah.axd"type="Elmah.ErrorLogPageFactory, Elmah" preCondition="integratedMode" />
      </handlers>
    </system.webServer>
  </location>
</configuration>

So here you can change “DefaultConnection “to sql server connection string name. I have use two module sql errorlog and Email settings .Other info you can follow thehttps://code.google.com/p/elmah/

No comments:

Post a Comment

http://blogsiteslist.com