我是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)
答案 0 :(得分:1)
我没有直接回答你的问题,而是一个有用的建议。 首先使用配置设置对其进行测试,这样您就可以快速消除与代码无关的任何外部问题。