2010-07-30 125 views

回答

3

对于任何日志记录/邮件/发生异常时您想要执行的操作,您应该查看Web.config文件中的应用程序运行状况配置(described here)。

在你的情况(在发生异常时发送邮件),你会在本例使用SimpleMailWebEventProvider提供商与预定义的“所有错误”的事件,如:

<healthMonitoring enabled="false" heartbeatInterval="0"> 
    <providers> 
    <add name="notifyAppDev" type="System.Web.Management.SimpleMailWebEventProvider" to="[email protected]" from="[email protected]" subjectPrefix="[WebEvent Error My Site Blabla]" buffer="false" /> 
    </providers> 
    <rules> 
    <add name="appDevEvents" eventName="All Errors" provider="notifyAppDev" profile="Critical" minInstances="1" maxLimit="Infinite" minInterval="00:01:00" custom="" /> 
    </rules> 
</healthMonitoring> 

哦,如果你想使用此方法不要忘记在Web.config文件中配置发送邮件的SMTP服务器。

+1

这是为mvc工作吗? – Blankman 2010-07-30 16:47:23

+0

是的,ASP.NET MVC使用与“经典”ASP.NET相同的核心,并与其他人共享此功能。 – Shtong 2010-07-30 16:53:31