Base solution for your next web application
Open Closed

Override Default Logger #5458


User avatar
0
ajayak created

I want to extend the default Logger to log errors to Sentry.

How can I extend the Logger implementation? I want to use the base logging functionality with the addition of my custom code.


2 Answer(s)
  • User Avatar
    0
    strix20 created

    You should just need a log4net appender set up.

    We use Graylog, so I don't have any experience with Sentry, but a cursory google search found this:

    [https://github.com/MCKanpolat/SharpRaven.Log4Net.Core])

  • User Avatar
    0
    ajayak created

    <cite>strix20: </cite> You should just need a log4net appender set up.

    We use Graylog, so I don't have any experience with Sentry, but a cursory google search found this:

    [https://github.com/MCKanpolat/SharpRaven.Log4Net.Core])

    Thanks @strix20 :)

    I found a simple solution as well. In my case, I only want real exceptions logged instead of UserFriendlyException. I did some exploration on AspNetBoilerplate docs and found this code to handle all types of exceptions:

    public class ExceptionHandler : IEventHandler<AbpHandledExceptionData>, ITransientDependency
    

    Now I can easily filter specific exceptions and log them to Sentry or any other service.