Elmah.MVC不会记录生产环境中的错误

时间:2012-07-27 06:04:19

标签: asp.net-mvc iis-7 elmah

我使用Elmah.MVC Nuget package将Elmah.MVC安装到我的MVC项目中。它在开发环境中工作正常,但是当我将网站上传到托管服务器(IIS7)时,它不会记录错误。

这是我的网络配置文件(仅限Elmah配置),

<?xml version="1.0" encoding="utf-8"?>
<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" />
            <section name="errorFilter" requirePermission="false" type="Elmah.ErrorFilterSectionHandler, Elmah" />
        </sectionGroup>
    </configSections>
    <connectionStrings>
    ...
    </connectionStrings>
    <appSettings>
        <add key="webpages:Version" value="1.0.0.0" />
        <add key="ClientValidationEnabled" value="true" />
        <add key="UnobtrusiveJavaScriptEnabled" value="true" />
        <add key="elmah.mvc.disableHandler" value="false" />
        <add key="elmah.mvc.requiresAuthentication" value="false" />
        <add key="elmah.mvc.allowedRoles" value="*" />
    </appSettings>

    <system.web>
        <customErrors mode="Off">
        </customErrors>
        ...
        <httpModules>
            <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />
            <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" />
            <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" />
        </httpModules>
    </system.web>
    <system.webServer>
        <validation validateIntegratedModeConfiguration="false" />
        <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>
        ...
    </system.webServer>
    ...
    <elmah>
        <security allowRemoteAccess="yes" />
        <errorLog type="Elmah.XmlFileErrorLog, Elmah" logPath="~/App_Data/Elmah.Errors" />
    </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>

有人请检查&amp;告诉你为什么它不在托管环境中记录错误?

2 个答案:

答案 0 :(得分:6)

您的应用程序是否具有生产环境中App_Data目录的写入权限?

根据您的配置,您没有登录到SQL - &gt;应用程序池标识需要能够修改/写入文件才能附加到App_Data / Elmah.Errors文件。 More information on the why and how.

答案 1 :(得分:3)

我有类似的问题。我正在使用这一行:

<errorLog type="Elmah.XmlFileErrorLog, Elmah" logPath="~\App_Data\Elmah.Errors" />

错误。你必须使用斜杠:

<errorLog type="Elmah.XmlFileErrorLog, Elmah" logPath="~/App_Data/Elmah.Errors" />

这应该是评论,但我没有足够的代表。