asp.net-mvcelmaherror-loggingelmah.mvc

Stop Elmah logging dynamically in ASP.Net MVC


I have implemented Elmah logging error by using this article in one of my applications and it is running fine as expected.

Now as per the requirements I have to stop logging error dynamically that will handle by the user either user will run logging error or not by simply set in web.config.

But I have no idea how to stop it dynamically and I have also read this article but I am not able to stop logging errors.

Is anything I am missing or I should change?


Solution

  • As suggested in the stackoverflow answer you link to, you can comment out the ErrorLog element from your Web.config. This doesn't disable logging (as suggested by the accepted answer), but switch to using the in-memory logger in ELMAH. This will log all errors in memory, which shouldn't slow down your installation. If you want to remove error logging completely, you can comment out all of the ELMAH-related modules in Web.config.

    If you want a toggle, I've described this in my ELMAH Tutorial. Create a new app setting:

    <add key="ELMAH:disable" value="false" />
    

    Then add the following code in your Global.asax.cs file:

    void ErrorLog_Filtering(object sender, ExceptionFilterEventArgs e)
    {
        if (bool.Parse(ConfigurationManager.AppSettings["ELMAH:disable"]))
            e.Dismiss();
    }