예제 #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);
        }
예제 #2
0
        public void Handle(LogEntryEvent eventToHandle)
        {
            var logEntry = eventToHandle.LogEntry;

            if (shouldAddMessageToLog(logEntry))
            {
                _view.AddLog(logEntry.Display);
            }
        }
예제 #3
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);
        }
 public LogEntryInstance(DatabaseContext databaseContext, ILogger <LogEntryHandler> logger, Func <Task <IdentityUser?> > getUserAsync, LogEntryEvent @event, Device?device = null, Sensor?sensor = null, Plant?plant = null)
 {
     this.logger          = logger;
     this.getUserAsync    = getUserAsync;
     this.databaseContext = databaseContext;
     this.@event          = @event;
     this.device          = device;
     this.sensor          = sensor;
     this.plant           = plant;
 }
 public LogEntryInstance AddLogEntry(LogEntryEvent @event, Device?device = null, Sensor?sensor = null, Plant?plant = null)
 {
     return(new LogEntryInstance(databaseContext, logEntryHandlerLogger, getUserAsync, @event, device: device, sensor: sensor, plant: plant));
 }