Exemplo n.º 1
0
        /// <summary>
        ///     Logs exception
        /// </summary>
        /// <param name="scope">Exception occurance scope</param>
        /// <param name="level">Severity level</param>
        /// <param name="exception">Exception object</param>
        public static void LogException(object scope, LogLevel level, Exception exception)
        {
            if (exception == null)
            {
                return;
            }
            if (level > Level || level == LogLevel.None || BannedScopes.Contains(scope.ToString()))
            {
                return;
            }
            var description = new StringBuilder($"EXCEPTION ({exception.GetType().GetTypeInfo().Name})\n");

            try
            {
                var tempException = exception;
                while (tempException != null)
                {
                    description.AppendLine(tempException.Message);
                    tempException = tempException.InnerException;
                }
                description.AppendLine(exception.StackTrace);
            }
            catch (Exception ex)
            {
                LogEntry(scope, level, $"Error logging exception: {ex.Message}");
            }

            var eventArgs = new LogEntryEventArgs(scope, level, description.ToString(), exception);

            LogEntryEvent?.Invoke(scope, eventArgs);
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Creates log notification
        /// </summary>
        /// <param name="scope">Message context</param>
        /// <param name="level">Severity level</param>
        /// <param name="message">Notification message</param>
        public static void LogEntry(object scope, LogLevel level, string message)
        {
            if (level > Level || level == LogLevel.None || BannedScopes.Contains(scope.ToString()))
            {
                return;
            }
            var eventArgs = new LogEntryEventArgs(scope, level, message);

            LogEntryEvent?.Invoke(scope, eventArgs);
        }
Exemplo n.º 3
0
 public static bool AddBannedScope(object scope)
 {
     lock (LockObject)
     {
         if (scope == null)
         {
             return(false);
         }
         var scopeName = scope.ToString();
         if (BannedScopes.Contains(scopeName))
         {
             return(false);
         }
         BannedScopes.Add(scopeName);
         return(true);
     }
 }