使用Elmah和ServiceStack

时间:2013-09-11 08:52:05

标签: servicestack elmah

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

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

以下是代码:

我在AppHost的构造函数中设置了LogManager.LogFactory:

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和电子邮件都已正确配置,我可以在App_Data/Elmah中看到错误的XML文件,因此正在记录错误..

1 个答案:

答案 0 :(得分:2)

要在使用Elmah和ServiceStack时接收电子邮件,请查看以下链接:

http://rossipedia.com/blog/2013/03/elmah-emails-and-servicestack/