SMTP Appender - log4net 问题

发布于 2024-11-17 00:00:26 字数 2205 浏览 5 评论 0原文

我的 SMTP 附加程序工作时遇到问题:

我有以下配置文件设置:

<log4net>
<appender name="LogFileAppender" type="log4net.Appender.FileAppender">
  <param name="File" value="folder\\filelog.log"/>
  <layout type="log4net.Layout.PatternLayout">
    <param name="ConversionPattern" value="%d [%t] %-5p %c %m%n"/>
  </layout>
</appender>
<appender name="SmtpAppender" type="log4net.Appender.SmtpAppender">
  <to value="[email protected]" />
  <from value="[email protected]" />
  <subject value="Error in site" />
  <smtpHost value="111.111.111.111" />
  <authentication value="1"/>
  <username Value="[email protected]" />
  <password value="password" />
  <port value="25" />
  <bufferSize value="1" />
  <lossy value="false" />
  <threshold value="ALL"/>
  <evaluator type="log4net.Core.LevelEvaluator">
    <threshold value="ALL"/>
  </evaluator>
  <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%newline%date [%thread] %-5level %logger [%property] - %message%newline%newline%newline" />
  </layout>
</appender>

<logger name="File">
  <level value="All" />
  <appender-ref ref="LogFileAppender" />
</logger>

<logger name="EmailAppender">
  <level value="ALL" />
  <appender-ref ref="SmtpAppender" />
</logger>

我正在尝试记录错误以查看是否收到电子邮件:

            log4net.Config.XmlConfigurator.Configure();
        ILog logger = LogManager.GetLogger("EmailAppender");
        logger.Error("uyyy: " + DateTime.Now.ToLongDateString());

电子邮件未到达。 如果我切换到“文件”,它会正确记录。

我知道我添加的凭据是正确的,因为我在系统的其他地方使用它们没有问题。

编辑:我尝试使用上面的“空白”配置运行,并且需要一段时间才能运行 logger.Error 行,然后再继续。有了我的真实详细信息,它就会立即运行,没有任何延迟。

I am having issues getting my SMTP appender working:

I have the follow config file setting:

<log4net>
<appender name="LogFileAppender" type="log4net.Appender.FileAppender">
  <param name="File" value="folder\\filelog.log"/>
  <layout type="log4net.Layout.PatternLayout">
    <param name="ConversionPattern" value="%d [%t] %-5p %c %m%n"/>
  </layout>
</appender>
<appender name="SmtpAppender" type="log4net.Appender.SmtpAppender">
  <to value="[email protected]" />
  <from value="[email protected]" />
  <subject value="Error in site" />
  <smtpHost value="111.111.111.111" />
  <authentication value="1"/>
  <username Value="[email protected]" />
  <password value="password" />
  <port value="25" />
  <bufferSize value="1" />
  <lossy value="false" />
  <threshold value="ALL"/>
  <evaluator type="log4net.Core.LevelEvaluator">
    <threshold value="ALL"/>
  </evaluator>
  <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%newline%date [%thread] %-5level %logger [%property] - %message%newline%newline%newline" />
  </layout>
</appender>

<logger name="File">
  <level value="All" />
  <appender-ref ref="LogFileAppender" />
</logger>

<logger name="EmailAppender">
  <level value="ALL" />
  <appender-ref ref="SmtpAppender" />
</logger>

I am trying to log an ERROR to see if I get the email:

            log4net.Config.XmlConfigurator.Configure();
        ILog logger = LogManager.GetLogger("EmailAppender");
        logger.Error("uyyy: " + DateTime.Now.ToLongDateString());

Email is not arriving.
If I switch to "File" it logs correctly.

I know the credentials I have added are correct, as I am using them elsewhere in the system without issue.

EDIT: I tried running with my above "blanked out" config, and it took a while to run the logger.Error line before continuing. With my real details, it runs straight away, without delay.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一曲爱恨情仇 2024-11-24 00:00:26

来自 - http://logging.apache.org/log4net/release /sdk/log4net.Appender.SmtpAppender.html

“注意......身份验证和设置服务器端口仅在 MS .NET 1.1 运行时可用。要使这些功能启用后,您需要确保您使用的是针对 MS .NET 1.1 框架构建的 log4net 程序集版本,并且您在 MS .NET 1.1 运行时上运行应用程序,并且仅向所有其他平台发送未经身份验证的消息。支持侦听端口 25(默认)的服务器。”

我不确定,但我认为这意味着任何在 .NET 1.1 之后版本上构建的应用程序,身份验证都将不起作用。您使用的是 1.1 或更高版本吗?

From - http://logging.apache.org/log4net/release/sdk/log4net.Appender.SmtpAppender.html

"CAUTION��� Authentication and setting the server Port are only available on the MS .NET 1.1 runtime. For these features to be enabled you need to ensure that you are using a version of the log4net assembly that is built against the MS .NET 1.1 framework and that you are running the your application on the MS .NET 1.1 runtime. On all other platforms only sending unauthenticated messages to a server listening on port 25 (the default) is supported."

I don't know for sure, but I take that to mean any application built on later .NET than 1.1, authentication will not work. Are you using 1.1, or later?

乱世争霸 2024-11-24 00:00:26

将其添加到配置部分的末尾,

    <appSettings>
         <add key="log4net.Internal.Debug" value="true"/>
    </appSettings>

您将能够跟踪错误

add this to end of the config section

    <appSettings>
         <add key="log4net.Internal.Debug" value="true"/>
    </appSettings>

you will able to trace error

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文