1

我的 log4net 配置如下

<appender name="RollingFile" type="log4net.Appender.RollingFileAppender">

  <!-- Edit to change your filename here -->
  <file value="Logs\\rolling.log" />

  <appendToFile value="true" />
  <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
  <rollingStyle value="Date" />
  <datePattern value=".yyyy-MM-dd'.log'" />
  <maximumFileSize value="10MB" />

  <!-- %identity used for ASP.NET app, %username used for windows app. You can leave them as is or remove one of them accordingly -->
  <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="[%date{dd MMM yyyy HH:mm:ss fff}] [%5level] (%identity-%username) %message%newline" />
  </layout>
</appender>

<appender name="SmtpAppender" type="log4net.Appender.SmtpAppender">
  <to value="***" />
  <from value="***" />
  <subject value="****" />
  <smtpHost value="localhost" />
  <bufferSize value="1" />
  <lossy value="true" />
  <evaluator type="log4net.Core.LevelEvaluator">
    <threshold value="ERROR"/>
  </evaluator>
  <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="[%date{dd MMM yyyy HH:mm:ss fff}] [%5level] (%identity-%username) %message%newline" />
  </layout>
</appender>

<root>
  <!-- Edit to change level of logging here, under normal conditions this should be set to INFO, use DEBUG level for verbose logging -->
  <level value="INFO" />
  <appender-ref ref="RollingFile" />
  <appender-ref ref="SmtpAppender" />
</root>

滚动文件附加程序工作正常,但是 SMTP 附加程序失败并出现以下错误 System.Net.Mail.SmtpException: Failure sending mail. ---> System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: An attempt was made to access a socket in a way forbidden by its access permissions [::1]:25

我觉得奇怪的是错误末尾的方括号不包含配置中的 SMTP 主机。我期待看到localhost那里。

我在本地机器上针对 smtp4dev 运行它。

谢谢!

4

1 回答 1

0

[::1] 表示法是表示环回地址的 IPV6 方式(双冒号表示法只是隐藏了不向地址添加信息的 0),因此消息只是告诉您附加程序正在尝试访问本地主机。

关于错误本身,可能是由于防病毒软件阻止了对您要使用的端口的访问,或者是防火墙阻止了连接。请检查您是否收到有关这些应用程序被阻止访问的消息。

于 2014-04-07T09:31:28.560 回答