Reputation: 2663
I am having issues getting my SMTP appender working:
I have the follow config file setting:
<log4net>
<appender name="LogFileAppender" type="log4net.Appender.FileAppender">
<param name="File" value="folder\\filelog.log"/>
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p %c %m%n"/>
</layout>
</appender>
<appender name="SmtpAppender" type="log4net.Appender.SmtpAppender">
<to value="[email protected]" />
<from value="[email protected]" />
<subject value="Error in site" />
<smtpHost value="111.111.111.111" />
<authentication value="1"/>
<username Value="[email protected]" />
<password value="password" />
<port value="25" />
<bufferSize value="1" />
<lossy value="false" />
<threshold value="ALL"/>
<evaluator type="log4net.Core.LevelEvaluator">
<threshold value="ALL"/>
</evaluator>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%newline%date [%thread] %-5level %logger [%property] - %message%newline%newline%newline" />
</layout>
</appender>
<logger name="File">
<level value="All" />
<appender-ref ref="LogFileAppender" />
</logger>
<logger name="EmailAppender">
<level value="ALL" />
<appender-ref ref="SmtpAppender" />
</logger>
I am trying to log an ERROR to see if I get the email:
log4net.Config.XmlConfigurator.Configure();
ILog logger = LogManager.GetLogger("EmailAppender");
logger.Error("uyyy: " + DateTime.Now.ToLongDateString());
Email is not arriving. If I switch to "File" it logs correctly.
I know the credentials I have added are correct, as I am using them elsewhere in the system without issue.
EDIT: I tried running with my above "blanked out" config, and it took a while to run the logger.Error line before continuing. With my real details, it runs straight away, without delay.
Upvotes: 3
Views: 1839
Reputation: 154
add this to end of the config section
<appSettings>
<add key="log4net.Internal.Debug" value="true"/>
</appSettings>
you will able to trace error
Upvotes: 0
Reputation: 11
From - http://logging.apache.org/log4net/release/sdk/log4net.Appender.SmtpAppender.html
"CAUTION��� Authentication and setting the server Port are only available on the MS .NET 1.1 runtime. For these features to be enabled you need to ensure that you are using a version of the log4net assembly that is built against the MS .NET 1.1 framework and that you are running the your application on the MS .NET 1.1 runtime. On all other platforms only sending unauthenticated messages to a server listening on port 25 (the default) is supported."
I don't know for sure, but I take that to mean any application built on later .NET than 1.1, authentication will not work. Are you using 1.1, or later?
Upvotes: 1