2008-10-13 68 views

回答

6

好吧,这很有趣,我现在正在写我自己的答案。

我做的是使用entlib的源代码。

在 Microsoft.Practices.EnterpriseLibrary.Logging和 Microsoft.Practices.EnterpriseLibrary.Logging.TraceListenerData

我发现我所需要的类。

  • 复制EmailMessage.cs到EmailMessageHTML.cs
  • 复制EmailTraceListener.cs到EmailHTMLTraceListener.cs
  • 复制EmailTraceListenerData.cs到EmailHTMLTraceListenerData.cs

在您自己的新图书馆将这些类项目。

在EmailMessageHTML改变所有构造函数来匹配新的类名和不是添加以下行的方法:

protected MailMessage CreateMailMessage() 
      { 
       ..... 

       message.IsBodyHtml = true; 
       ..... 

       return message; 
      } 

在那之后,我不得不使用这个新EmailMessageHTML类EmailHTMLTraceListener(改变EmailMessage到EmailMessageHTML)和也可以在新的EmailHTMLTraceListenerData.cs文件中使用此EmailHTMLTraceListener。

编译这个新项目,比使用在你的配置如下(例子)

<loggingConfiguration 
name="Logging Application Block" 
tracingEnabled="true" 
defaultCategory="" 
logWarningsWhenNoCategoriesMatch="true"> 
    <listeners> 
     <add toAddress="[email protected]"   
     fromAddress="[email protected]" 
     subjectLineStarter="" 
     subjectLineEnder="My HTMLemailLogger" 
     smtpServer="localhost" smtpPort="25" 
     formatter="Text Formatter"       
     listenerDataType="MYLibrary.HTMLEmailLogger.EmailHTMLTraceListenerData, 
     MYLibrary.HTMLEmailLogger, Version=2.0.0.0, 
     Culture=neutral, 
     PublicKeyToken=null" 
     traceOutputOptions="None" 
     type="MYLibrary.HTMLEmailLogger.EmailHTMLTraceListener, 
     MYLibrary.HTMLEmailLogger, 
     Version=2.0.0.0, 
     Culture=neutral, 
     PublicKeyToken=null" 
     name="EmailHTML TraceListener"/> 
    </listeners> 
</loggingConfiguration> 

,并添加一个有效的类别此登录到课程:

<add switchValue="All" name="OutOfBalanceBooking"> 
    <listeners> 
     <add name="Database Trace Listener"/> 
     <add name="EmailHTML TraceListener"/> 
    </listeners> 
</add> 

当然,你需要一些HTML文档要比使用EntLib进行日志记录。我把它作为读者的练习。 的确如此!我现在收到一封很好的HTML电子邮件,用于客户在网站上进行的每一次错误预订...

+1

干得好。以上面的工作为例,并完全实现了这一点。在这里写下步骤。 http://trycatch.me/implementing-html-formatted-emails-in-the-enterprise-library-logging-block/ – 2013-05-23 13:30:32

相关问题