Event args containing information about a message that has been written to a log.
Наследование: System.EventArgs
 private void OnLogMessage(object sender, LogMessageEventArgs e)
 {
     if (e.LogEvent != LogEvent.Debug)
     {
         if (!e.Message.Contains("Catel"))
         {
             LogMessage.SafeInvoke(this, e);
         }
     }
 }
        public void Constructor_ManualDateTime()
        {
            var log = new Log(GetType());
            var eventArgs = new LogMessageEventArgs(log, "log message", 42, null, LogEvent.Warning, DateTime.Today);

            Assert.AreEqual(log, eventArgs.Log);
            Assert.AreEqual("log message", eventArgs.Message);
            Assert.AreEqual(42, eventArgs.ExtraData);
            Assert.AreEqual(LogEvent.Warning, eventArgs.LogEvent);
            Assert.AreEqual(DateTime.Today, eventArgs.Time);
        }
        public void Constructor_AutomaticDateTime()
        {
            var log = new Log(GetType());
            var eventArgs = new LogMessageEventArgs(log, "log message", 42, null, LogEvent.Error);

            Assert.AreEqual(log, eventArgs.Log);
            Assert.AreEqual("log message", eventArgs.Message);
            Assert.AreEqual(42, eventArgs.ExtraData);
            Assert.AreEqual(LogEvent.Error, eventArgs.LogEvent);
            Assert.AreEqual(0, (int)DateTime.Now.Subtract(eventArgs.Time).TotalSeconds);
        }
Пример #4
0
        /// <summary>
        /// Called when one of the logs has written a log message.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="Catel.Logging.LogMessageEventArgs"/> instance containing the event data.</param>
        /// <exception cref="ArgumentOutOfRangeException">The <see cref="LogEvent"/> is not supported.</exception>
        private static void OnLogMessage(object sender, LogMessageEventArgs e)
        {
            LogMessage.SafeInvoke(sender, e);

            if (!LogInfo.IsLogEventEnabled(e.LogEvent))
            {
                return;
            }

            lock (_logListeners)
            {
                if (_logListeners.Count == 0)
                {
                    return;
                }

                foreach (var listener in _logListeners)
                {
                    if (IsListenerInterested(listener, e.LogEvent))
                    {
                        listener.Write(e.Log, e.Message, e.LogEvent, e.ExtraData);

                        switch (e.LogEvent)
                        {
                        case LogEvent.Debug:
                            listener.Debug(e.Log, e.Message, e.ExtraData);
                            break;

                        case LogEvent.Info:
                            listener.Info(e.Log, e.Message, e.ExtraData);
                            break;

                        case LogEvent.Warning:
                            listener.Warning(e.Log, e.Message, e.ExtraData);
                            break;

                        case LogEvent.Error:
                            listener.Error(e.Log, e.Message, e.ExtraData);
                            break;

                        default:
                            throw new ArgumentOutOfRangeException();
                        }
                    }
                }
            }
        }
Пример #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LogEntry" /> class.
 /// </summary>
 /// <param name="eventArgs">The event args.</param>
 public LogEntry(LogMessageEventArgs eventArgs)
     : this(eventArgs.Log, eventArgs.Message, eventArgs.LogEvent, eventArgs.ExtraData, eventArgs.Time)
 {
 }
Пример #6
0
 /// <summary>
 /// Raises the <see cref="LogMessage" /> event.
 /// </summary>
 /// <param name="message">The message.</param>
 /// <param name="extraData">The extra data.</param>
 /// <param name="logEvent">The log event.</param>
 /// <exception cref="ArgumentNullException">The <paramref name="message" /> is <c>null</c>.</exception>
 private void WriteMessage(string message, object extraData, LogEvent logEvent)
 {
     var logMessage = LogMessage;
     if (logMessage != null)
     {
         var eventArgs = new LogMessageEventArgs(this, string.Format("{0}{1}", new string(' ', IndentLevel * IndentSize), message), extraData, logEvent, DateTime.Now);
         logMessage(this, eventArgs);
     }
 }
Пример #7
0
        /// <summary>
        /// Called when one of the logs has written a log message.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="Catel.Logging.LogMessageEventArgs"/> instance containing the event data.</param>
        /// <exception cref="ArgumentOutOfRangeException">The <see cref="LogEvent"/> is not supported.</exception>
        private static void OnLogMessage(object sender, LogMessageEventArgs e)
        {
            if (LogInfo.IgnoreCatelLogging && e.Log.IsCatelLogging)
            {
                return;
            }

            if (!LogInfo.IsLogEventEnabled(e.LogEvent))
            {
                return;
            }

            LogMessage.SafeInvoke(sender, e);

            lock (_logListeners)
            {
                if (_logListeners.Count == 0)
                {
                    return;
                }

                foreach (var listener in _logListeners)
                {
                    if (IsListenerInterested(listener, e.LogEvent))
                    {
                        listener.Write(e.Log, e.Message, e.LogEvent, e.ExtraData, e.Time);

                        switch (e.LogEvent)
                        {
                            case LogEvent.Debug:
                                listener.Debug(e.Log, e.Message, e.ExtraData, e.Time);
                                break;

                            case LogEvent.Info:
                                listener.Info(e.Log, e.Message, e.ExtraData, e.Time);
                                break;

                            case LogEvent.Warning:
                                listener.Warning(e.Log, e.Message, e.ExtraData, e.Time);
                                break;

                            case LogEvent.Error:
                                listener.Error(e.Log, e.Message, e.ExtraData, e.Time);
                                break;

                            default:
                                throw new ArgumentOutOfRangeException();
                        }
                    }
                }
            }
        }
Пример #8
0
        private void OnLogMessage(object sender, LogMessageEventArgs e)
        {
            if (_isClearingLog)
            {
                return;
            }

            var logEntry = new LogEntry(e);

            logEntry.Data["ThreadId"] = ThreadHelper.GetCurrentThreadId();

            lock (_lock)
            {
                _logEntries.Add(logEntry);

                if (!_isUpdatingTypes)
                {
                    var typeNames = TypeNames;
                    if (!typeNames.Contains(logEntry.Log.TargetType.Name))
                    {
                        _isUpdatingTypes = true;

                        try
                        {
                            typeNames.Add(logEntry.Log.TargetType.Name);
                        }
                        catch (System.Exception)
                        {
                            // we don't have time for this, let it go...
                        }

                        _isUpdatingTypes = false;
                    }
                }
            }

            UpdateEntriesCount(logEntry);

            LogMessage.SafeInvoke(this, new LogEntryEventArgs(logEntry));
        }
Пример #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LogEntry" /> class.
 /// </summary>
 /// <param name="eventArgs">The event args.</param>
 public LogEntry(LogMessageEventArgs eventArgs)
     : this(eventArgs.Log, eventArgs.Message, eventArgs.LogEvent, eventArgs.ExtraData, eventArgs.Time)
 {
 }
 private void OnConsoleServiceLogMessage(object sender, LogMessageEventArgs e)
 {
     Output += e.Message + System.Environment.NewLine;
 }
Пример #11
0
        /// <summary>
        /// Raises the <see cref="LogMessage" /> event.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="extraData">The extra data.</param>
        /// <param name="logEvent">The log event.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="message" /> is <c>null</c>.</exception>
        private void WriteMessage(string message, object extraData, LogEvent logEvent)
        {
            Argument.IsNotNull("message", message);
            Argument.IsNotNull("logEvent", logEvent);

            var logMessage = LogMessage;
            if (logMessage != null)
            {
                var eventArgs = new LogMessageEventArgs(this, string.Format("[{0}] {1}{2}", TargetType.FullName, new string(' ', IndentLevel * IndentSize), message), extraData, logEvent);
                logMessage(this, eventArgs);
            }
        }
Пример #12
0
        private void OnLogMessage(object sender, LogMessageEventArgs e)
        {
            var logEntry = new LogEntry(e);
            if (!logEntry.Data.ContainsKey("ThreadId"))
            {
                logEntry.Data["ThreadId"] = ThreadHelper.GetCurrentThreadId();
            }

            AddLogEntries(new[] { logEntry });
        }
Пример #13
0
        /// <summary>
        /// Called when one of the logs has written a log message.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="Catel.Logging.LogMessageEventArgs"/> instance containing the event data.</param>
        /// <exception cref="ArgumentOutOfRangeException">The <see cref="LogEvent"/> is not supported.</exception>
        private static void OnLogMessage(object sender, LogMessageEventArgs e)
        {
            LogMessage.SafeInvoke(sender, e);

            lock (_logListeners)
            {
                foreach (var listener in _logListeners)
                {
                    if (IsListenerInterested(listener, e.LogEvent))
                    {
                        listener.Write(e.Log, e.Message, e.LogEvent, e.ExtraData);

                        switch (e.LogEvent)
                        {
                            case LogEvent.Debug:
                                listener.Debug(e.Log, e.Message, e.ExtraData);
                                break;

                            case LogEvent.Info:
                                listener.Info(e.Log, e.Message, e.ExtraData);
                                break;

                            case LogEvent.Warning:
                                listener.Warning(e.Log, e.Message, e.ExtraData);
                                break;

                            case LogEvent.Error:
                                listener.Error(e.Log, e.Message, e.ExtraData);
                                break;

                            default:
                                throw new ArgumentOutOfRangeException();
                        }
                    }
                }
            }
        }
Пример #14
0
        /// <summary>
        /// Called when one of the logs has written a log message.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="Catel.Logging.LogMessageEventArgs"/> instance containing the event data.</param>
        /// <exception cref="ArgumentOutOfRangeException">The <see cref="LogEvent"/> is not supported.</exception>
        private static void OnLogMessage(object sender, LogMessageEventArgs e)
        {
            if (LogInfo.IgnoreCatelLogging && e.Log.IsCatelLogging)
            {
                return;
            }

            if (!LogInfo.IsLogEventEnabled(e.LogEvent))
            {
                return;
            }

            LogMessage.SafeInvoke(sender, e);

            var logListeners = GetThreadSafeLogListeners();
            if (logListeners.Count == 0)
            {
                return;
            }

            foreach (var listener in logListeners)
            {
                if (IsListenerInterested(listener, e.LogEvent))
                {
                    listener.Write(e.Log, e.Message, e.LogEvent, e.ExtraData, e.LogData, e.Time);

                    switch (e.LogEvent)
                    {
                        case LogEvent.Debug:
                            listener.Debug(e.Log, e.Message, e.ExtraData, e.LogData, e.Time);
                            break;

                        case LogEvent.Info:
                            listener.Info(e.Log, e.Message, e.ExtraData, e.LogData, e.Time);
                            break;

                        case LogEvent.Warning:
                            listener.Warning(e.Log, e.Message, e.ExtraData, e.LogData, e.Time);
                            break;

                        case LogEvent.Error:
                            listener.Error(e.Log, e.Message, e.ExtraData, e.LogData, e.Time);
                            break;

                        case LogEvent.Status:
                            listener.Status(e.Log, e.Message, e.ExtraData, e.LogData, e.Time);
                            break;
                    }
                }
            }
        }