问题
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.
回答1:
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.
回答2:
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();
}
来源:https://stackoverflow.com/questions/25393171/how-to-stop-elmah-logging