To enable log4net's internal logging for troubleshooting, see the FAQ:

http://logging.apache.org/log4net/release/manual/faq.html#internalDebug

You can find configuration examples for the appenders you mention here:

http://logging.apache.org/log4net/release/config-examples.html

Regards,

Dag


-----Original Message-----
From: Rutledge, J. Mike [mailto:[EMAIL PROTECTED] 
Sent: 7. mars 2005 20:19
To: Log4NET User
Subject: problems.


I've been trying my best to find code samples for using several of the
appenders so I wouldn't bother you good folks. So far I've had no luck.
I can find the config file entries but nothing else.

Here is what I'd like to do:

Use the SMTPAppender and SmtpPickupDirAppender. I can't get either to
work.
I assume that in the code you don't have to tell it what appender it is
using (it's specified in the config file).

Also, is there a way to trap errors in the logger itself? With these
appenders in the config file, it prevents the fileappender from working.
Fileappender works when I remove the SmtpPickupDirAppender references.

Any help would be appreciated. This is such a cool tool. If I could get
the email portion to work, that and the fileappender would cover 98% of
what I do.

Thanks,
Rut


configfile

<?xml version="1.0" encoding="utf-8" ?>
<log4net>

<appender name="MyFirstFileAppender"
        type="log4net.Appender.FileAppender">
        <file value="c:\\testfile.txt" />
        <appendToFile value="true" />
        <layout type="log4net.Layout.PatternLayout">
                <conversionPattern value="%5p %d (%c:%L) - %m%n" />
        </layout>
</appender>

<appender name="SMTPAppender" type="log4net.Appender.SMTPAppender">
            <BufferSize value="1" />
            <param name="To" value="[EMAIL PROTECTED]" />
            <param name="From" value="[EMAIL PROTECTED]" />
            <Subject value="log4net Error Message" />
            <SMTPHost value="mail.rjr.com" />
            <param name="LocationInfo" value="false" />
            <param name="BufferSize" value="512" />
            <param name="Lossy" value="true" />
            <evaluator type="log4net.spi.LevelEvaluator">
                <param name="Threshold" value="ALL" />
            </evaluator>
            <layout type="log4net.Layout.PatternLayout">
                <param name="ConversionPattern" value="%n%d [%t] %-5p %c
[%x] - %m%n%n%n" />
            </layout>
</appender>

<appender name="SmtpPickupDirAppender"
type="log4net.Appender.SmtpPickupDirAppender">
        <to value="[EMAIL PROTECTED]" />
        <from value="[EMAIL PROTECTED]" />
        <subject value="test logging message" />
        <pickupDir value="C:\\SmtpPickup" />
        <bufferSize value="512" />
        <lossy value="true" />
        <evaluator type="log4net.Core.LevelEvaluator">
                <threshold value="ALL"/>
        </evaluator>
        <layout type="log4net.Layout.PatternLayout">
                <conversionPattern value="%newline%date [%thread]
%-5level %logger [%ndc] - % message%newline%newline%newline" />
        </layout>
</appender>


<root>
        <level value="ALL" />
        <appender-ref ref="MyFirstFileAppender" />
        <appender-ref ref="SMTPAppender" />
        <appender-ref ref="SmtpPickupDirAppender /> </root>

</log4net>




c# code

string log4netConfigFilePath = Path.Combine
(AppDomain.CurrentDomain.SetupInformation.ApplicationBase,
                                "log4net.config");

        
log4net.Config.DOMConfigurator.ConfigureAndWatch(new
                                FileInfo(log4netConfigFilePath));

                        log4net.Config.DOMConfigurator.Configure();

                        log4net.ILog log  =
log4net.LogManager.GetLogger(typeof(Form1));
                                
                        try
                        {
                                log.Info("NEW");
                                log.Info("Another");
                        }
                        catch
                        {
                                MessageBox.Show("here");
                        }

Reply via email to