Пример #1
0
        /// <summary>
        /// Compose a log message
        /// </summary>
        /// <param name="dateTime">Time label</param>
        /// <param name="category">Message category</param>
        /// <param name="source">Message source</param>
        /// <param name="message">Additional message</param>
        /// <returns>Composed message</returns>
        public ILogMessage CreateMessage(
            DateTime dateTime,
            LogMessageCategoryEnum category,
            string source,
            string message
            )
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }

            var result = DoCreate(
                dateTime,
                category,
                false,
                false,
                source,
                message,
                string.Empty,
                string.Empty,
                null
                );

            return
                result;
        }
Пример #2
0
        public CLogMessage(
            IMessageSerializer messageSerializer,

            DateTime timeStamp,
            LogMessageCategoryEnum messageCategory,
            bool isException,
            bool isRootMessage,
            string source,
            string message,
            string messageStackTrace,
            string exceptionStackTrace,

            ILogMessage childMessage
            )
        {
            if (messageSerializer == null)
            {
                throw new ArgumentNullException("messageSerializer");
            }
            //childMessage allowed to be null

            _messageSerializer = messageSerializer;

            _timeStamp = timeStamp;
            _messageCategory = messageCategory;
            _isException = isException;
            _isRootMessage = isRootMessage;
            _source = source;
            _message = message.CrLnNormalize();
            _messageStackTrace = messageStackTrace.CrLnNormalize();
            _exceptionStackTrace = exceptionStackTrace.CrLnNormalize();

            _childMessage = childMessage;
        }
Пример #3
0
        /// <summary>
        /// Write categorized message to logger.
        /// (it's easier to use LogMessage + LogWarning methods instead).
        /// </summary>
        public void LogCategorizedMessage(
            LogMessageCategoryEnum category,
            string source,
            string message
            )
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }

            if (_disposed)
            {
                //skip a logging work when logger has disposed

                return;
            }
            
            lock(_locker)
            {
                _logger.LogCategorizedMessage(
                    category,
                    source,
                    message
                    );
            }
        }
Пример #4
0
        /// <summary>
        /// Write categorized message to logger.
        /// (it's easier to use LogMessage + LogWarning methods instead).
        /// </summary>
        public void LogCategorizedMessage(
            LogMessageCategoryEnum category,
            string source,
            string message
            )
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }

            if (_disposed)
            {
                //skip a logging work when logger has disposed

                return;
            }
            
            try
            {
                _logger.LogCategorizedMessage(
                    category,
                    source,
                    message
                    );
            }
            catch
            {
                //no way to log any logger error
                //nothing can be done here
                //force this error to be skipped
            }
        }
Пример #5
0
        /// <summary>
        /// Записать сообщение в протокол
        /// </summary>
        public void LogCategorizedMessage(
            LogMessageCategoryEnum category,
            string source,
            string message
            )
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }

            if (_disposed)
            {
                //в случае, если логгер задиспозен, просто игнорируем новые сообщения не выбрасывая исключений

                return;
            }

            foreach (var logger in _loggers)
            {
                try
                {
                    logger.LogCategorizedMessage(
                        category,
                        source,
                        message
                        );
                }
                catch
                {
                    //no way to log any logger error
                    //nothing can be done here

                    //force this error to be skipped
                    //and log message into others loggers
                }
            }
        }
Пример #6
0
        /// <summary>
        /// Write categorized message to logger.
        /// (it's easier to use LogMessage + LogWarning methods instead).
        /// </summary>
        public void LogCategorizedMessage(
            LogMessageCategoryEnum category,
            string source,
            string message
            )
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }

            if (_disposed)
            {
                //skip a logging work when logger has disposed

                return;
            }

            var dateTime = AmbientContext.Now;

            var logMessage = _logMessageFactory.CreateMessage(
                dateTime,
                category,
                source,
                message
                );

            var writeMessage = logMessage.ConvertToString();

            _writeAction(
                writeMessage
                );
        }
Пример #7
0
            public LogItemContainer(
                LogMessageCategoryEnum category,
                string source,
                string message
                )
            {
                if (source == null)
                {
                    throw new ArgumentNullException("source");
                }
                if (message == null)
                {
                    throw new ArgumentNullException("message");
                }

                Category = category;
                Source = source;
                Message = message;
            }
Пример #8
0
        /// <summary>
        /// Write categorized message to logger.
        /// (it's easier to use LogMessage + LogWarning methods instead).
        /// </summary>
        public void LogCategorizedMessage(
            LogMessageCategoryEnum category,
            string source,
            string message
            )
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }

            if (_disposed)
            {
                //skip a logging work when logger has disposed

                return;
            }

            //если еще не стартовали - стартуем
            if (Interlocked.CompareExchange(ref _started, 1, 0) == 0)
            {
                this.WorkStart();
            }

            var i = new LogItemContainer(
                category,
                source,
                message
                );

            _logQueue.Enqueue(i);

            _logItemStoredEvent.Set();
        }
Пример #9
0
        private ILogMessage DoCreate(
            DateTime dateTime,
            LogMessageCategoryEnum messageCategory,
            bool isException,
            bool isRootMessage,
            string strSource,
            string strMessage,
            string strExceptionStackTrace,
            string strMessageStackTrace,
            ILogMessage innerLogMessage
            )
        {
            ILogMessage result = null;

            try
            {
                strExceptionStackTrace = StackNormalize(strExceptionStackTrace, false);
                strMessageStackTrace = StackNormalize(strMessageStackTrace, true);

                result = new CLogMessage(
                    _messageSerializer,

                    dateTime,
                    messageCategory,
                    isException,
                    isRootMessage,
                    strSource,
                    strMessage,
                    strMessageStackTrace,
                    strExceptionStackTrace,
                    innerLogMessage
                    );
            }
            catch
            {
                //no way to log any logger error
                //use fake message in this case

                result = FakeLogMessage;
            }

            return
                result;
        }