Hi, thanks for your help!
Now I've managed to send my first loggingmail using log4j.

Do you know if you can set up a SMTPAppender
without using a configurationfile?

For the FileAppender I do the following and it works:

// For logging.
private Category cat;
        .
        .
        .
// Create a default PatternLayout.
PatternLayout pl = new
PatternLayout(PatternLayout.DEFAULT_CONVERSION_PATTERN);

// Create a new FileAppender with the PatternLayout above and the path
// to where it should write it's output.
FileAppender fa = new FileAppender(pl, file);

// Add the FileAppender to the Category.
cat.addAppender(fa);



I tried the following for the SMTPAppender but it doesn't seem to work:

// For logging.
private Category cat;
        .
        .
        .
// Create a new SMTPAppender.
SMTPAppender smtpa = new SMTPAppender();

// Initialize the SMTPAppender.
smtpa.setOption(SMTPAppender.TO_OPTION,
"[EMAIL PROTECTED]");
smtpa.setOption(SMTPAppender.FROM_OPTION, "someone");
smtpa.setOption(SMTPAppender.SUBJECT_OPTION, "about");
smtpa.setOption(SMTPAppender.SMTP_HOST_OPTION, "my_host");      
smtpa.setOption(SMTPAppender.EVALUATOR_CLASS_OPTION,
"fully.qualified.name.MailEventEvaluator");

// Add the SMTPAppender to the Category.
cat.addAppender(smtpa);



Can you see what the problem is?

--Mattias Ahlin



> -----Original Message-----
> From: Ayehou Mesfin [mailto:[EMAIL PROTECTED]]
> Sent: den 29 januari 2001 18:35
> To: LOG4J Users Mailing List
> Subject: Re: SMTPAppender
> 
> 
> I myself had a hard time to figure out
> that the event triggering the SMTPAppender
> has to at least be an ERROR event, i.e.
> you will not get any email if the event
> is with less priority than error.
> 
> To make that happen you have to write your
> own EventEvaluator.
> I have included the piece of code which
> you can use to achieve just that. Note that
> the last row in the configuration file
> points out that our new EventEvaluator should
> be used instead of the default one.
> 
> Lycka till!
> 
> <configuration file>
> log4j.rootCategory= , mail
> 
> log4j.appender.mail=org.apache.log4j.net.SMTPAppender
> [EMAIL PROTECTED]
> log4j.appender.mail.From=someone
> log4j.appender.mail.Subject=about
> log4j.appender.mail.SMTPHost=smtp.host.com
> log4j.appender.mail.layout=org.apache.log4j.PatternLayout
> log4j.appender.mail.layout.ConversionPattern=%d [%t]
> %-5p %c - %m%n
> log4j.appender.mail.EvaluatorClass=MailEventEvaluator
> </configuration file>
> 
> <MailEventEvaluator.java>
> import org.apache.log4j.Priority;
> import org.apache.log4j.spi.TriggeringEventEvaluator;
> import org.apache.log4j.spi.LoggingEvent;
> 
> public class MailEventEvaluator implements
> TriggeringEventEvaluator
> {
>     public boolean isTriggeringEvent (LoggingEvent
> event)
>     {
>         return event.priority.isGreaterOrEqual
> (Priority.DEBUG);
>     }
> }
> </MailEventEvaluator.java>
> --- "Ahlin, Mattias"
> <[EMAIL PROTECTED]> wrote:
> > Hi everyone!
> > 
> > I can't figure out how to use the SMTPAppender.
> > 
> > Is there anyone that have a short example of
> > how to initialize it?
> > 
> > 
> > --Mattias Ahlin
> > 
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> > [EMAIL PROTECTED]
> > For additional commands, e-mail:
> > [EMAIL PROTECTED]
> > 
> 
> 
> __________________________________________________
> Do You Yahoo!?
> Yahoo! Auctions - Buy the things you want at great prices. 
> http://auctions.yahoo.com/
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to