3

我正在尝试将 Elmah 与 ServiceStack 一起使用,但遇到以下问题:

  • 当我访问/elmah.axd我的网站时,它会返回 404,而不是显示 Elmah 日志记录页面。
  • 电子邮件似乎没有发送

这是代码:

我在以下构造函数中设置了 LogManager.LogFactory AppHost

public AppHost() //Tell ServiceStack the name and where to find your web services
    : base("StarterTemplate ASP.NET Host", typeof(HomeService).Assembly)
{
    LogManager.LogFactory = new ElmahLogFactory(new NLogFactory());
}

web.config我声明了以下部分:

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


<system.web>
    <compilation debug="true" targetFramework="4.0" />
    <httpHandlers>
        <add path="*" type="ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory, ServiceStack" verb="*" />
        <add verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" />
    </httpHandlers>
    <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>
    <modules runAllManagedModulesForAllRequests="true" />
    <validation validateIntegratedModeConfiguration="false" />
    <handlers>
        <add path="*" name="ServiceStack.Factory" type="ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory, ServiceStack" verb="*" preCondition="integratedMode" resourceType="Unspecified" allowPathInfo="true" />
        <add name="Elmah" path="elmah.axd" verb="POST,GET,HEAD" type="Elmah.ErrorLogPageFactory, Elmah" preCondition="integratedMode" />
    </handlers>
    <modules>
        <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>

<location path="elmah.axd">
    <system.webServer>
        <handlers>
            <remove name="ServiceStack.Factory" />
        </handlers>
    </system.webServer>
</location>

<elmah>
    <security allowRemoteAccess="true" />
    <errorLog type="Elmah.XmlFileErrorLog, Elmah" logPath="~/App_Data/Elmah" />
    <errorMail from="elmaherror@domain.com" to="myemail@domain.com" async="false" smtpServer="192.168.0.5" smtpPort="25" userName="" password="" />
</elmah>

SMTPServer 和电子邮件都配置正确,我可以看到错误 XML 文件,App_Data/Elmah因此正在记录错误。

4

0 回答 0