Beispiel #1
0
        /// <summary>
        /// Logs unhandled exceptions when user context is available
        /// </summary>
        /// <param name="user"></param>
        /// <param name="ex"></param>
        /// <returns></returns>
        public async Task LogUnhandledException(System.Security.Claims.ClaimsPrincipal user, Exception ex)
        {
            VerboseError error = GetError(user, ex);

            error.source += " - Unhandled Exception";
            await _loggerQuery.LogError(error);
        }
Beispiel #2
0
        public async Task <bool> LogError(VerboseError error)
        {
            try
            {
                using (var db = _database)
                {
                    var connection = db.Connection as MySqlConnection;
                    await connection.OpenAsync();

                    string query = @"INSERT INTO occasions.errors "
                                   + @"(source, errorMessage, innerException, stackTrace, date) "
                                   + @"VALUES(@source, @errorMessage, @innerException, @stackTrace, @date); "
                                   + @"SELECT * FROM occasions.errors WHERE id = LAST_INSERT_ID();";

                    var result = connection.QueryFirstAsync <int>(query, error).Result;
                    if (result > 0)
                    {
                        return(true);
                    }
                    return(false);
                }
            }
            catch (Exception)
            {
                return(false);
            }
        }
Beispiel #3
0
        private VerboseError GetError(Exception ex)
        {
            VerboseError error = new VerboseError
            {
                source         = "Unhandled Exception",
                errorMessage   = ex.Message,
                innerException = ex.InnerException != null?ex.InnerException.ToString() : String.Empty,
                                     stackTrace = ex.StackTrace,
                                     date       = DateTime.Now
            };

            return(error);
        }
Beispiel #4
0
        private VerboseError GetError(System.Security.Claims.ClaimsPrincipal user, Exception ex)
        {
            VerboseError error = new VerboseError
            {
                source         = ExtractUserName(user),
                errorMessage   = ex.Message,
                innerException = ex.InnerException != null?ex.InnerException.ToString() : String.Empty,
                                     stackTrace = ex.StackTrace,
                                     date       = DateTime.Now
            };

            return(error);
        }
Beispiel #5
0
        public void LogError_ReturnsNull()
        {
            var error = new VerboseError {
                source = "test", errorMessage = "error"
            };

            __loggerQueryMock.Setup(x => x.LogError(error))
            .Returns(Task.Factory.StartNew(() => true));

            var user      = new System.Security.Claims.ClaimsPrincipal();
            var exception = new Exception();

            var task = _sut.LogError(user, exception);

            Assert.True(task.IsCompletedSuccessfully);
        }
Beispiel #6
0
 /// <summary>
 /// Logs handled errors
 /// </summary>
 /// <param name="user"></param>
 /// <param name="ex"></param>
 /// <returns></returns>
 public async Task LogError(System.Security.Claims.ClaimsPrincipal user, Exception ex)
 {
     VerboseError error = GetError(user, ex);
     await _loggerQuery.LogError(error);
 }
Beispiel #7
0
 /// <summary>
 /// Logs unhandled exceptions when user context is not available
 /// </summary>
 /// <param name="ex"></param>
 /// <returns></returns>
 public async Task LogUnhandledException(Exception ex)
 {
     VerboseError error = GetError(ex);
     await _loggerQuery.LogError(error);
 }