I have a console program (.Net 4.5) with multiple appenders. File appender works fine, some smtp appenders work and one does not.
All smtp appenders send mail on application closing, even if buffers are not full, except SmtpAppenderError that sends nothing. I tried to:
- see debug info from log4net in console, no config errors;
- watch the buffers in the BufferingAppenderSkeleton collection and my messages are all there;
- send to different recipients;
- use log level filters;
- Swap filters: if I configure SmtpAppenderOK to log "ERROR:" and SmtpAppenderError to log "FP:" then I get mails with ERROR: from SmtpAppenderOK and I do not get anything from SmtpAppenderError.
In most cases file, Ok and Error appenders are used, anyway DELETE works fine even if other appenders have messages in queue. Do you have any idea?
Here is my config:
<appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender">
<param name="File" value="C:\\Log\\myprogram\\log-" />
<datePattern value="yyyy-MM.dd'.log'" />
<param name="AppendToFile" value="true" />
<param name="Encoding" value="utf-8" />
<param name="RollingStyle" value="Date" />
<param name="StaticLogFileName" value="false" />
<param name="maxSizeRollBackups" value="90" />
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%5p [%d] - %m%n" />
</layout>
</appender>
<appender name="SmtpAppenderError" type="log4net.Appender.SmtpAppender">
<to value="[email protected]" />
<from value="[email protected]" />
<subject value="Error in program" />
<smtpHost value="mail.somewhere.com" />
<port value="25" />
<authentication value="Basic" />
<username value="[email protected]" />
<password value="secret!" />
<bufferSize value="9999" />
<lossy value="false" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%newline%date - %message%newline" />
</layout>
<filter type="log4net.Filter.StringMatchFilter">
<stringToMatch value="ERROR:" />
<acceptOnMatch value="true" />
</filter>
<filter type="log4net.Filter.DenyAllFilter" />
</appender>
<appender name="SmtpAppenderOK" type="log4net.Appender.SmtpAppender">
<to value="[email protected]" />
<from value="[email protected]" />
<subject value="All right!" />
<smtpHost value="mail.somewhere.com" />
<port value="25" />
<authentication value="Basic" />
<username value="[email protected]" />
<password value="secret!" />
<bufferSize value="9999" />
<lossy value="false" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%newline%date - %message%newline" />
</layout>
<filter type="log4net.Filter.StringMatchFilter">
<stringToMatch value="FP:" />
<acceptOnMatch value="true" />
</filter>
<filter type="log4net.Filter.DenyAllFilter" />
</appender>
<appender name="SmtpAppenderDELETE" type="log4net.Appender.SmtpAppender">
<to value="[email protected]" />
<from value="[email protected]" />
<subject value="deleting..." />
<smtpHost value="mail.somewhere.com" />
<port value="25" />
<authentication value="Basic" />
<username value="[email protected]" />
<password value="secret!" />
<bufferSize value="999" />
<lossy value="false" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%newline%date - %message%newline" />
</layout>
<filter type="log4net.Filter.StringMatchFilter">
<stringToMatch value="FP:delete" />
<acceptOnMatch value="true" />
</filter>
<filter type="log4net.Filter.DenyAllFilter" />
</appender>
<root>
<level value="ALL" />
<appender-ref ref="SmtpAppenderError" />
<appender-ref ref="LogFileAppender" />
<appender-ref ref="SmtpAppenderOK" />
<appender-ref ref="SmtpAppenderDELETE" />
</root>
I solved it by changing the order of the appenders, all SMTP first, then file appender.