Elmah.MVC does not log errors in production environment

こ雲淡風輕ζ 提交于 2019-12-24 00:07:49

问题


I installed Elmah.MVC to my MVC project using Elmah.MVC Nuget package. It works fine in development environment, but when I upload website to hosting server (IIS7) it does not log errors.

This is my web config file (only the Elmah configuraion),

<?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>

Can someone please check & tell why it is not logging errors in Hosting environment?


回答1:


Does your application have write access to the App_Data directory in your production environment?

Based on your configuration, you are not logging to SQL -> the application pool identity will need to be able to modify/write to files in order to append to the App_Data/Elmah.Errors file. More information on the why and how.




回答2:


I had a similar problem. I was using this line:

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

Wrong. You must use slash:

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

This should be a comment, but I have not enough rep.



来源:https://stackoverflow.com/questions/11682295/elmah-mvc-does-not-log-errors-in-production-environment

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!