Exception Logging In TC10

I am trying to create an service which will log exceptions to the exceptions log in the admin panel.

As I understand it CSException() shouldn't be used anymore and this is the right way to do this. I've based this on examples I've found around the web but It isn't working for me, I get nothing logged. I would like to log errors with my own category and have full control over them.

  public class ExceptionService : Exception, IUserRenderableException, ILoggableException
    {
        private readonly Func<string> _getTranslatedMessage;

        public ExceptionService(string internalMessage, Exception inner) :
            this(internalMessage, null, inner)
        {
        }

        public ExceptionService(string internalMessage, Func<string> getTranslatedMessage = null) :
            base(internalMessage)
        {
            _getTranslatedMessage = getTranslatedMessage;
        }

        public ExceptionService(string internalMessage, Func<string> getTranslatedMessage, Exception inner) :
            base(internalMessage, inner)
        {
            _getTranslatedMessage = getTranslatedMessage;
        }

        public string GetUserRenderableMessage()
        {
            if (_getTranslatedMessage != null)
            {
                return _getTranslatedMessage();
            }

            return "Internal Error Occured";
        }

        public string GetUserRenderableMessage()
        {
            if (_getTranslatedMessage != null)
            {
                return _getTranslatedMessage();
            }

            return "Internal Error Occured";
        }

        public string Category
        {
            get
            {
                return "MyCategory";
            }
        }
    }

new ExceptionService($"an error happened with x: {someinfo}");

Can I please get some info on how to get this to work correctly for logging errors?

Parents
No Data
Reply
  • It appears that support for ILoggableException was disrupted during some exception refactoring. For now, you could still use CSException (which isn't upgrade safe, but will work). I've logged a bug to address the issue with ILoggableException:

Children