是否有人有教程链接或有关如何使用Logging块发送错误电子邮件的示例?
杰克
答案 0 :(得分:6)
您需要在Logging Application Block中设置EmailTraceListener。
您可以使用Enterprise Library UI,但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通过发送命令行电子邮件来检查它。