您需要在日志应用程序块中设置emailTraceListener。
您可以使用企业库用户界面,但是web.config部分看起来像这样:
<loggingConfiguration name="Logging Application Block" tracingEnabled="true" defaultCategory="Default" logWarningsWhenNoCategoriesMatch="true">
<listeners>
<add toAddress="admin@company.com" fromAddress="fromemail@company.com"
subjectLineStarter="" subjectLineEnder="" smtpServer="127.0.0.1"
smtpPort="25" formatter="" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.EmailTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
traceOutputOptions="None" filter="All" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.EmailTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
name="Email" />
</listeners>
<categorySources>
<add switchValue="All" name="Default">
<listeners>
<add name="Email" />
</listeners>
</add>
</categorySources>
</loggingConfiguration>
如果您的smtp服务器设置正确,这将起作用。您可以使用telnet发送命令行电子邮件来检查。