I have the following SmtpAppender configuration for log4net:
<appender name="AlchemySmtpAppender" type="log4net.Appender.SmtpAppender">
<to value="[email protected]" />
<from value="[email protected]" />
<subject value="Fatal error on Web Portal" />
<smtpHost value="ValidHost" />
<username value="myUserName"/>
<password value="myPassword"/>
<lossy value="false" />
<bufferSize value="0"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%newline%date [%thread] %-5level %logger - %message%newline%newline%newline" />
</layout>
</appender>
<root>
<level value="DEBUG" />
<appender-ref ref="AlchemySmtpAppender" />
</root>
The email never sends though.
I've enabled the internal debugging and checked the trace/output and found the following:
log4net: Loading Appender [SmtpAppender] type: [log4net.Appender.SmtpAppender]
log4net: Setting Property [To] to String value [[email protected]]
log4net: Setting Property [From] to String value [[email protected]]
log4net: Setting Property [Subject] to String value [Fatal error on Web Portal]
log4net: Setting Property [SmtpHost] to String value [ValidHost]
log4net: Setting Property [Username] to String value [myUserName]
log4net: Setting Property [Password] to String value [myPassword]
log4net: Setting Property [Lossy] to Boolean value [False]
log4net: Setting Property [BufferSize] to Int32 value [0]
log4net: Converter [message] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [newline] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Setting Property [ConversionPattern] to String value [%newline%date [%thread] %-5level %logger - %message%newline%newline%newline]
log4net: Converter [newline] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [date] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [literal] Option [ [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [thread] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [literal] Option [] ] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [level] Option [] Format [min=5,max=2147483647,leftAlign=True]
log4net: Converter [literal] Option [ ] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [logger] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [literal] Option [ - ] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [message] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [newline] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [newline] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [newline] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Setting Property [Layout] to object [log4net.Layout.PatternLayout]
log4net: reated Appender [SmtpAppender]
log4net: Adding appender named [SmtpAppender] to logger [root].
log4net: Hierarchy Threshold []
No errors that I can see, yet no email either. The email addresses, credentials and host are all valid because we use them in the System.Net section of the web.config file as well and they work perfectly.
Anyone know what I could be doing wrong in my configuration? Or perhaps there's some other form of troubleshooting I can do to figure it out?
Using other appenders like RollingFile, Trace and AdoNetAppender works perfectly fine too.
I managed to resolve my problem by installing smtp4dev and configuring log4net to use the dummy host I setup.
Just to confirm in case someone needs to do this:
Hope that helps.