MS SQL Server ELMAH with Web API

  1. For your WebApi project, Nuget the following 3 packages:
    1. ELMAH
    2. ELMAH Core Library
    3. ELMAH on MS SQL Server
  2. Create a new database on the SQL server.
  3. Run the script “Elmah.SqlServer.sql” under App_Readme folder. The script will create the necessary table and stored procs in the database.
  4. Modify your web.config connection string for “elmah-sqlserver”
  5. Modify Global.asax.cs


public class WebApiApplication : System.Web.HttpApplication


    protected void Application_Start()









        GlobalConfiguration.Configuration.Filters.Add(new MyExceptionFilter());




public class MyExceptionFilter : ExceptionFilterAttribute


    public override void OnException(HttpActionExecutedContext context)


        Elmah.ErrorLog.GetDefault(HttpContext.Current).Log(new Elmah.Error(context.Exception));




Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s