public void Activity_ExceptionLogger()
        {
            var preSaveCount  = TypeExtension.DefaultInteger;
            var postSaveCount = TypeExtension.DefaultInteger;

            Tables.DropMigrationHistory();

            ExceptionLogger log1 = new ExceptionLogger("DefaultConnection", "Activity");

            preSaveCount = ExceptionLogger.GetAll("DefaultConnection", "Activity").Count();
            log1.Save();
            postSaveCount = ExceptionLogger.GetAll("DefaultConnection", "Activity").Count();
            Assert.IsTrue(log1.ExceptionLogID != TypeExtension.DefaultInteger, "ActivityLogger threw exception.");
            Assert.IsTrue(postSaveCount == preSaveCount + 1);

            // Your custom schema
            ExceptionLogger log2 = new ExceptionLogger("DefaultConnection", "MySchema");

            preSaveCount = ExceptionLogger.GetAll("DefaultConnection", "Activity").Count();
            log2.Save();
            postSaveCount = ExceptionLogger.GetAll("DefaultConnection", "Activity").Count();
            Assert.IsTrue(log2.ExceptionLogID != TypeExtension.DefaultInteger, "ActivityLogger threw exception.");
            Assert.IsTrue(postSaveCount == preSaveCount + 1);
        }
        public ApiResponse GetRecentExceptions([FromQuery] int?top, [FromQuery] string endpoint, [FromQuery] string app, [FromQuery] string routine)
        {
            try
            {
                if (!top.HasValue)
                {
                    top = 20;
                }
                if (top > 800)
                {
                    top = 800;
                }

                string[] endpointLookup = null;
                string[] appLookup      = null;

                if (string.IsNullOrEmpty(endpoint) || endpoint.Equals("all", StringComparison.OrdinalIgnoreCase))
                {
                    endpoint = null;
                }
                if (string.IsNullOrEmpty(app) || app.Equals("all", StringComparison.OrdinalIgnoreCase))
                {
                    app = null;
                }
                if (string.IsNullOrEmpty(routine))
                {
                    routine = null;
                }

                if (endpoint != null)
                {
                    endpointLookup = endpoint.Split(',', StringSplitOptions.RemoveEmptyEntries);

                    if (endpointLookup.FirstOrDefault(e => e.Equals("all", StringComparison.OrdinalIgnoreCase)) != null)
                    {
                        endpointLookup = null;
                    }
                }

                if (app != null)
                {
                    appLookup = app.Split(',', StringSplitOptions.RemoveEmptyEntries);

                    if (appLookup.FirstOrDefault(a => a.Equals("all", StringComparison.OrdinalIgnoreCase)) != null)
                    {
                        appLookup = null;
                    }
                }

                var ret = from exception in ExceptionLogger.GetAll(endpointLookup)
                          where exception.HasAppTitle(appLookup) &&
                          (routine == null || (exception.execOptions?.MatchRoutine(routine) ?? false))
                          orderby exception.created.Ticks descending
                          select new
                {
                    id = exception.sId,
                    exception.created,
                    message = exception.message.Left(200, true),           // limit exception message length to something reasonable
                    exception.procedure,
                    exception.appTitle,
                    exception.appVersion,
                    relatedCount = exception.related?.Count ?? 0
                }
                ;

                return(ApiResponse.Payload(new
                {
                    Results = ret.Take(Math.Min(top.Value, ret.Count())),
                    TotalExceptionCnt = ExceptionLogger.TotalCnt
                }));
            }
            catch (Exception ex)
            {
                SessionLog.Exception(ex);
                return(ApiResponse.Exception(ex));
            }
        }