我是 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)