16

I am using log4net for sending mails when any app error occurs. I have configured the log4net but mail is not recd. Following is the config:

    <appender name="SmtpAppender" type="log4net.Appender.SmtpAppender">
        <to value="aagrawal@inco.com"/>
        <from value="aagrawal@inco.com"/>
        <subject value="ERROR | MRM Application"/>
        <smtpHost value="relaymail.sapient.com"/>
        <bufferSize value="512"/>
        <lossy value="true"/>
        <evaluator type="log4net.Core.LevelEvaluator">
            <threshold value="ALL"/>
        </evaluator>
        <layout type="log4net.Layout.PatternLayout,log4net">
            <conversionPattern value="%property{log4net:HostName} :: %level :: %message %newlineLogger: %logger%newlineThread: %thread%newlineDate: %date%newlineNDC: %property{NDC}%newline%newline"/>
        </layout>
    </appender>

Is there any other changes that needs to be made?

Philipp M
  • 1,877
  • 7
  • 27
  • 38
Ankit
  • 281
  • 3
  • 4
  • 8

5 Answers5

14

It looks good. To see some log4net debug messages in your console add the following lines in your app.config

  <appSettings>
    <add key="log4net.Internal.Debug" value="true"/>
  </appSettings>

Maybe this will give you a hint.

  • 2
    I found this article to be helpful, it describes in more detail how to do this: http://david.gardiner.net.au/2008/11/log4nets-smtpappender-with-multiple.html – Aaron D Jan 10 '13 at 05:23
  • If you add this app setting to your web application, notice that log4net uses the tracing infrastructure in System.Diagnostics to output debug information. So you need to make sure you have tracing set up. Take a look at the article @AaronD linked to, to see an example of setting up tracing to output to a textfile. – René Sep 18 '13 at 09:46
12

Check if you need SMTP authentication.

Also bufferSize value="512" means it will collect 512 messages before sending an email. I'm pretty sure you don't want that.

Mauricio Scheffer
  • 98,863
  • 23
  • 192
  • 275
  • 2
    I modified it to 1. still not getting any mails. Is there any other configuration that needs to be done apart from web.config – Ankit Feb 09 '10 at 12:48
6

I also found out that the appender has to be referenced in the root element like such:

    <root>
      <level value="INFO"/>
      <appender-ref ref="LogFileAppender"/>
      <appender-ref ref="ConsoleAppender"/>
      <appender-ref ref="SmtpAppender"/>      
    </root>
  </log4net>
M Akin
  • 446
  • 6
  • 18
5
<lossy value="false" />

it helped for me

Yaplex
  • 2,272
  • 1
  • 20
  • 38
0

I will share my case for not received emails with SmtpAppender. The organization that I'm working has restrictions/polices for group emails.
The <to value="aagrawal@inco.com"/> value in my case was a group email example: developers@office.com, but if I change it to my personal mail it works.

Finally the solutions was to make new credentials for sending mails. Also tried every solution in this thread, (thanks by the way) in the log4net debugging logs there aren't any errors.

Also checked this questions:

Sometimes it's good to check your system administration for these configurations like in my case. They could resolve your issues.

mihkov
  • 1,171
  • 13
  • 37