0

I have an ASP.NET web app that uses log4net to log to various appenders. I have successfully added a SmtpAppender with a LevelEvaluator and can get e-mails to be sent with this; however if I replace this with a TimeEvaluator I cannot get e-mails to send.

My appender with the LevelEvaluator looks like this (this is working):

<appender name="EmailErrorAppender" type="log4net.Appender.SmtpAppender">
    <to value="to@myemail" />
    <from value="from@myemail" />
    <subject value="Alert Subject" />
    <smtpHost value="mymailhost" />
    <bufferSize value="50" />
    <lossy value="true" />
    <filter type="log4net.Filter.LevelRangeFilter">
        <levelMin value="ERROR" />
        <levelMax value="FATAL" />
    </filter>
    <evaluator type="log4net.Core.LevelEvaluator">
        <threshold value="ERROR"/>
    </evaluator>
    <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date [%thread] %-5level %logger%newline%newline" />
    </layout>
</appender>

The problematic appender with the TimeEvaluator looks like this (this is not working):

<appender name="EmailErrorAppender" type="log4net.Appender.SmtpAppender">
    <to value="to@myemail" />
    <from value="from@myemail" />
    <subject value="Alert Subject" />
    <smtpHost value="mymailhost" />
    <bufferSize value="50" />
    <lossy value="true" />
    <filter type="log4net.Filter.LevelRangeFilter">
        <levelMin value="ERROR" />
        <levelMax value="FATAL" />
    </filter>
    <evaluator type="log4net.Core.TimeEvaluator">
        <interval value="30"/>
    </evaluator>
    <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date [%thread] %-5level %logger%newline%newline" />
    </layout>
</appender>

I've checked log4net's internal debug and it says it is loading it fine.

I would appreciate any help - is TimeEvaluator broken in an ASP.NET web context?

alergy
  • 974
  • 1
  • 14
  • 28
  • I cannot reproduce this problem. Are you sure that what you are seeing is not the expected behavior? TimeEvaluator will let an event pass only at most every seconds. You have no log event at all? If you also log to a file, does it log anything? – samy May 29 '15 at 08:14
  • @samy - I've got a custom fallback appender (logs to SQL and then file if SQL fails) at the root level alongside the `SmtpAppender`. This is working fine - so if I log an Error event I see it in the DB, but don't get an e-mail when using the `TimeEvaluator`. As mentioned with the `LevelEvaluator` it's fine. I was wondering if the time constraint is something that doesn't play well with the ASP.NET site. – alergy May 29 '15 at 09:10
  • It's worth saying that the class we use to log is a bespoke generic class (it was designed to be able to consume different logging libraries). It is instantiated at an application level, and in this case it ultimately has a private property for the instance of the log4net class - this private property is instantiated when the parent class is instantiated and does not change, so I **don't** believe that the log object is being re-initialised with every web page call - it persists at an Application level – alergy May 29 '15 at 09:32

0 Answers0