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 Reply Children