views:

423

answers:

1

Hello

I am a beginner in log4net and I am trying to add an appender in my code and then to send an email in case of an Error. I dont want to use a config file. My program runs but I never receive the email. Can you please let me know what's wrong in my code

    Dim test2 As log4net.Appender.SmtpAppender = New log4net.Appender.SmtpAppender()
    test2.To = [email protected]
    test2.From = [email protected]
    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)

Thank you for your help

+1  A: 

I don't have a direct answer to your question, but a useful suggestion. Test it using the configuration setup first, that way you can quickly eliminate any external problems unrelated to your code.

moomi
This is very good advice.
calico-cat