1

我是 log4net 的初学者,我正在尝试在我的代码中添加一个 appender,然后在出现错误时发送电子邮件。我不想使用配置文件。我的程序运行,但我从未收到电子邮件。我的代码有什么问题?

Dim test2 As log4net.Appender.SmtpAppender = New log4net.Appender.SmtpAppender()
test2.To = toto@hotmail.com
test2.From = toto@hotmail.com
test2.Subject = "test Email report"
test2.SmtpHost = "localhost"
test2.BufferSize = 1
test2.Lossy = true

Dim layout As log4net.Layout.PatternLayout = New log4net.Layout.PatternLayout()
layout.ConversionPattern = "%newline%message"
test2.Layout = layout
test2.ActivateOptions()


Dim l As log4net.Repository.Hierarchy.Logger = log4net.LogManager.GetLogger("EmailLog").Logger
l.Level = log4net.Core.Level.Error
l.Additivity = True
l.Repository.Configured = True
l.AddAppender(test2)


msg = "test test test" & vbNewLine & vbNewLine


Dim logger As log4net.ILog = log4net.LogManager.GetLogger("EmailLog")
logger.Error(msg)
4

1 回答 1

1

我没有直接回答您的问题,但有一个有用的建议。首先使用配置设置对其进行测试,这样您就可以快速消除与您的代码无关的任何外部问题。

于 2009-12-09T21:36:16.140 回答