Base solution for your next web application
Open Closed

Extend default ILogger implementation: Log4NetLogger #6672


User avatar
0
abarref created

The default implementation of ILogger is Abp.Castle.Logging.Log4Net.Log4NetLogger.

I need to extend its functionality so when logging an exception it also sends an email.

What would be the best approach for this?

The Log4NetLogger class has no virtual methods. Should I copy the entire class and customize it as desired?

Thanks


4 Answer(s)
  • User Avatar
    1
    maliming created
    Support Team

    You can send mail directly using Log4Net. see:https://logging.apache.org/log4net/release/config-examples.html#smtpappender

  • User Avatar
    0
    abarref created

    Thanks. Indeed that seems like the easiest approach.

  • User Avatar
    0
    abarref created

    Tried the SmtpAppender and couldn't make it work. Enabled internal logging of log4net and found that the SmtpAppender is not available in .Net Core. The same issue as described here: smtpappender-missing-in-log4net-2-0-8-nuget

    I'll go with custom Log4NetLogger approach another day with some more time.

  • User Avatar
    1
    maliming created
    Support Team

    You can also change the log component, such as NLOG(https://github.com/NLog/NLog/wiki/Mail-target), which supports the net core very well.