6

I am using Elmah.MVC 2 with MVC3, ASP.NET 4.5 on Azure Websites.

I have set it up to log, via the web.config, to XML files on the webserver. This all works. However I want to stop it temporarily, as I believe it may be slowing the web server, since it is taking up time writing these error files. I plan to log to SQL Server. But for now I need to stop Elmah.

My Web.config Elmah sections are :

    <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" />
  <section name="errorFilter" requirePermission="false" type="Elmah.ErrorFilterSectionHandler, Elmah" />
</sectionGroup>

and

<add key="elmah.mvc.disableHandler" value="true" />
<add key="elmah.mvc.disableHandleErrorFilter" value="false" />
<add key="elmah.mvc.requiresAuthentication" value="true" />
<add key="elmah.mvc.IgnoreDefaultRoute" value="false" />
<add key="elmah.mvc.allowedRoles" value="Admin" />
<add key="elmah.mvc.allowedUsers" value="Admin" />
<add key="elmah.mvc.route" value="elmah" />

and

<httpModules>
  <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />
  <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" />
  <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" />
</httpModules>

and

<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
  <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" preCondition="managedHandler" />
  <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" preCondition="managedHandler" />
  <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" preCondition="managedHandler" />
</modules>

and

  <elmah>
    <security allowRemoteAccess="yes" />
    <errorLog type="Elmah.SqlErrorLog, Elmah" connectionStringName="myDatabaseCS" />
    <errorLog type="Elmah.XmlFileErrorLog, Elmah" logPath="~/App_Data" />
    </elmah>
</configuration>

I thought this line stopped it:

    <add key="elmah.mvc.disableHandler" value="true" />

But alas not. However I cannot get to the Elmah page ie /Elmah just returns me to the login page.

How can I stop Elmah logging?

Thanks.

EDIT 1:

it may be to do with this in Global.asa:

//filters.Add(new ElmahHandledErrorLoggerFilter());
filters.Add(new HandleErrorAttribute());

THe first line is commented out as I do not believe it is required in V2. All error handling is now merged with Elmah I believe.

SamJolly
  • 6,347
  • 13
  • 59
  • 125

2 Answers2

13

Just remove the <errorLog> elements from your <elmah> section. Or comment it out. This will disable the logging functionality, and all you have to do to restore functionality when you want it is add those <errorLog> elements back in again. This way, you don't have to remove any of the core Elmah components that could lead to problems later on when you want to restore functionality, particularly if you miss something.

Chris Paton
  • 5,113
  • 4
  • 41
  • 52
  • Thanks for this. Very helpful. Do you have a view on whether my suspicion that XML file error logging could slow the server done, due to time taken to write the files away? – SamJolly Aug 19 '14 at 22:40
  • This did the trick. Although still interested in your view on performance impact of writing these files. – SamJolly Aug 19 '14 at 23:20
  • 2
    @SamJolly - Why would it slow down your server? It should only be writing anything if there are unhandled exceptions, which should be a rare occurance. If you're having unhandled exceptions occur frequently enough to be considered a performance issue, then you need to address that problem first. – Erik Funkenbusch Aug 20 '14 at 05:15
  • 1
    I agree with Erik. If you were logging to a database, then there may be issues there (depending on your db location, network speeds etc). I highly doubt the XML logging will give you speed issues. Use Glimpse (find it in NuGet) and use that to give you an idea of how your web app is performing. It's a great tool that every .NET developer should know. – Chris Paton Aug 20 '14 at 07:52
  • Thanks for this enlightenment, especially about Glimpse. The XML Logging things was a suspicion, but unfounded, based on your feedback. I have come across Glimpse, and seen articles on Glimpse working with Elmah, but am not using it yet.... that is until today :) – SamJolly Aug 20 '14 at 08:54
4

Just to note - removing <errorLog> from <elmah> in web.config does not stop the logging, it just reverts it to in-memory logging as described in this SO answer. (cannot comment on the accepted answer due to insufficient rep.)

If the intent is to stop logging entirely, you can use the Elmah's ErrorFilterModule (assuming that it is added in web.config) for that, like so (global.asax.cs excerpt):

protected void ErrorMail_Filtering(object sender, ExceptionFilterEventArgs e)
{
    e.Dismiss();
}
Community
  • 1
  • 1
davke
  • 350
  • 1
  • 7