使用带有企业库5日志记录块的App.Config的“ mailSettings”部分

|| 我正在尝试设置一些控制台应用程序以使用Enterprise Library 5 Logging Block。 我已经在我的app.config文件中定义了必要的元素,并且我知道它们可以正常工作,因为事件日志跟踪侦听器可以正常工作。问题出在我的电子邮件跟踪侦听器上。本质上,我宁愿使用“ 0”配置部分,而不是单独配置多个电子邮件侦听器(也可以将DEBUG版本的“发送”电子邮件发送到本地目录,而不是实际的电子邮件)。我的配置看起来像这样:
<configuration>
  <configSections>
    <section name=\"loggingConfiguration\" type=\"Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35\" requirePermission=\"true\" />
  </configSections>
  <loggingConfiguration name=\"\" tracingEnabled=\"true\" defaultCategory=\"General\">
    <listeners>
      <add name=\"Email Trace Listener\"
           type=\"Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.EmailTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35\"
           listenerDataType=\"Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.EmailTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35\"
           toAddress=\"some@address\"
           fromAddress=\"some@address\"
           subjectLineStarter=\"APPLICATION -- \"
           subjectLineEnder=\" -- Release\"
           filter=\"Information\"
           formatter=\"Text Formatter\" />
      <add name=\"Informational Email\"
           type=\"Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.EmailTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35\"
           listenerDataType=\"Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.EmailTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35\"
           toAddress=\"some@address\"
           fromAddress=\"some@address\"
           subjectLineStarter=\"APPLICATION -- \"
           subjectLineEnder=\" -- Release\"
           formatter=\"Minimalist Text Formatter\" />
    </listeners>
    <formatters>
      <add type=\"Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35\"
           template=\"Timestamp: {timestamp}{newline}&#xA;Message: {message}{newline}&#xA;Category: {category}{newline}&#xA;Priority: {priority}{newline}&#xA;EventId: {eventid}{newline}&#xA;Severity: {severity}{newline}&#xA;Title:{title}{newline}&#xA;Machine: {localMachine}{newline}&#xA;App Domain: {localAppDomain}{newline}&#xA;ProcessId: {localProcessId}{newline}&#xA;Process Name: {localProcessName}{newline}&#xA;Thread Name: {threadName}{newline}&#xA;Win32 ThreadId:{win32ThreadId}{newline}&#xA;Extended Properties: {dictionary({key} - {value}{newline})}\"
           name=\"Text Formatter\" />
      <add type=\"Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35\"
           template=\"Timestamp: {timestamp}{newline}&#xA;Title:{title}{newline}&#xA;Message: {message}{newline}&#xA;Priority: {priority}{newline}&#xA;EventId: {eventid}{newline}&#xA;Machine: {localMachine}{newline}&#xA;App Domain: {localAppDomain}{newline}&#xA;ProcessId: {localProcessId}{newline}&#xA;Process Name: {localProcessName}{newline}&#xA;Extended Properties: {dictionary({key} - {value}{newline})}\"
           name=\"Minimalist Text Formatter\" />
    </formatters>
    <categorySources>
      <add switchValue=\"All\" name=\"General\">
        <listeners>
          <add name=\"Event Log Listener\" />
          <add name=\"Email Trace Listener\" />
        </listeners>
      </add>
      <add switchValue=\"Information\" name=\"Email\">
        <listeners>
          <add name=\"Informational Email\" />
        </listeners>
      </add>
    </categorySources>
    <specialSources>
      <allEvents switchValue=\"All\" name=\"All Events\" />
      <notProcessed switchValue=\"All\" name=\"Unprocessed Category\">
        <listeners>
          <add name=\"Event Log Listener\" />
        </listeners>
      </notProcessed>
      <errors switchValue=\"Error\" name=\"Logging Errors &amp; Warnings\">
        <listeners>
          <add name=\"Email Trace Listener\" />
        </listeners>
      </errors>
    </specialSources>
  </loggingConfiguration>
  <startup>
    <supportedRuntime version=\"v4.0\" sku=\".NETFramework,Version=v4.0\"/>
  </startup>
  <system.net>
    <mailSettings>
      <smtp deliveryMethod=\"Network\">
        <network host=\"valid.local.SMTP.server\"/>
        <specifiedPickupDirectory pickupDirectoryLocation=\"C:\\Temp\"/>
      </smtp>
    </mailSettings>
  </system.net>
</configuration>
当我将“ 2”更改为“ 3”时,所有电子邮件都会按预期写出到配置的目录中。但是,如果将其设置为“网络”,则不会发送电子邮件。 我通过一个Web应用程序验证了我们几乎相同的设置,使其可以与Network配置一起正常工作。我没有看到有关无法发送电子邮件的其他事件日志消息(它实际上没有被记录,或者被吞下了……)。我不知所措,无法继续进行此工作。还有其他人遇到过这个问题吗?     
已邀请:
        找出问题。显然,如果希望它使用在“ 0”中配置的SMTP主机,则仍需要为跟踪侦听器的smtpServer属性指定一个空白字符串。所以代替这个:
<add name=\"Email Trace Listener\"
     type=\"Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.EmailTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35\"
     listenerDataType=\"Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.EmailTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35\"
     toAddress=\"some@address\"
     fromAddress=\"some@address\"
     subjectLineStarter=\"APPLICATION -- \"
     subjectLineEnder=\" -- Release\"
     filter=\"Information\"
     formatter=\"Text Formatter\" />
您需要使用此:
<add name=\"Email Trace Listener\"
     type=\"Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.EmailTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35\"
     listenerDataType=\"Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.EmailTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35\"
     toAddress=\"some@address\"
     fromAddress=\"some@address\"
     subjectLineStarter=\"APPLICATION -- \"
     subjectLineEnder=\" -- Release\"
     filter=\"Information\"
     smtpServer=\"\"
     formatter=\"Text Formatter\" />
显然,关闭该属性并不意味着它将像我最初想的那样将主机的空字符串传递给SmtpClient。     

要回复问题请先登录注册