Exemplo n.º 1
0
        /// <inheritdoc/>
        public void SendObject(
            string leftMessage,
            object rightObject,
            MessageLevelEnum messageLevel = MessageLevelEnum.Debug)
        {
            if (!IsEnabled)
            {
                return;
            }

            if (string.IsNullOrWhiteSpace(leftMessage))
            {
                throw new ArgumentException(DevConstants.ValueCannotBeNullOrWhitespace, nameof(leftMessage));
            }
            if (rightObject is null)
            {
                throw new ArgumentNullException(nameof(rightObject));
            }

            try
            {
                _traceDictionary[messageLevel]
                .SendObject(leftMessage, rightObject);
            }
            catch (ArgumentOutOfRangeException) { }
        }
Exemplo n.º 2
0
        /// <inheritdoc/>
        public void SendToTraceWindow(
            string key,
            string leftMessage,
            string rightMessage,
            MessageLevelEnum messageLevel = MessageLevelEnum.Debug)
        {
            if (!IsEnabled)
            {
                return;
            }

            if (string.IsNullOrWhiteSpace(key))
            {
                throw new ArgumentException("Value cannot be null or whitespace.", nameof(key));
            }
            if (string.IsNullOrWhiteSpace(leftMessage))
            {
                throw new ArgumentException("Value cannot be null or whitespace.", nameof(leftMessage));
            }
            if (string.IsNullOrWhiteSpace(rightMessage))
            {
                throw new ArgumentException("Value cannot be null or whitespace.", nameof(rightMessage));
            }

            if (_traceWindowDictionary.TryGetValue(key, out var traceWindow))
            {
                try
                {
                    _windowDictionary[messageLevel](traceWindow)
                    .Send(leftMessage, rightMessage);
                }
                catch (ArgumentOutOfRangeException) { }
            }
        }
Exemplo n.º 3
0
        /// <inheritdoc/>
        public void SendDump(
            string leftMessage,
            string shortTitle,
            byte[] address,
            int count,
            MessageLevelEnum messageLevel = MessageLevelEnum.Debug)
        {
            if (!IsEnabled)
            {
                return;
            }

            if (address is null)
            {
                throw new ArgumentNullException(nameof(address));
            }
            if (string.IsNullOrWhiteSpace(leftMessage))
            {
                throw new ArgumentException(DevConstants.ValueCannotBeNullOrWhitespace, nameof(leftMessage));
            }
            if (string.IsNullOrWhiteSpace(shortTitle))
            {
                throw new ArgumentException(DevConstants.ValueCannotBeNullOrWhitespace, nameof(shortTitle));
            }

            try
            {
                _traceDictionary[messageLevel]
                .SendDump(leftMessage, shortTitle, address, count);
            }
            catch (ArgumentOutOfRangeException) { }
        }
Exemplo n.º 4
0
        ///  <summary>
        ///      Specialised constructor for use only by derived class.
        ///  </summary>
        /// <param name="sender">       Source of the event. </param>
        /// <param name="message">      The message. </param>
        /// <param name="messageLevel"> The message level. </param>
        /// <param name="callerFile">   The caller file. </param>
        /// <param name="methodName">   Name of the method. </param>
        /// <param name="lineNumber">   The line number. </param>
        protected BaseMessage(
            object sender,
            string message,
            MessageLevelEnum messageLevel,
            string callerFile = null,
            string methodName = null,
            int lineNumber    = 0) : base(sender)
        {
            if (string.IsNullOrWhiteSpace(callerFile))
            {
                throw new ArgumentException(nameof(callerFile));
            }
            if (string.IsNullOrWhiteSpace(methodName))
            {
                throw new ArgumentException(nameof(methodName));
            }
            if (lineNumber <= 0)
            {
                throw new ArgumentException(nameof(lineNumber));
            }

            Message      = message;
            MessageLevel = messageLevel;
            ClassName    = Path.GetFileNameWithoutExtension(callerFile);
            MethodName   = methodName;
            LineNumber   = lineNumber;
        }
 /// <inheritdoc />
 public void SendToTraceWindow <T>(
     string traceWindowKey,
     string leftMessage,
     T rightMessage,
     MessageLevelEnum messageLevel = MessageLevelEnum.Debug)
 {
 }
Exemplo n.º 6
0
        /// <inheritdoc/>
        public void ExitMethod(
            string leftMessage,
            string rightMessage,
            MessageLevelEnum messageLevel = MessageLevelEnum.Debug)
        {
            if (!IsEnabled)
            {
                return;
            }

            if (string.IsNullOrWhiteSpace(leftMessage))
            {
                throw new ArgumentException(DevConstants.ValueCannotBeNullOrWhitespace, nameof(leftMessage));
            }
            if (string.IsNullOrWhiteSpace(rightMessage))
            {
                throw new ArgumentException(DevConstants.ValueCannotBeNullOrWhitespace, nameof(rightMessage));
            }

            try
            {
                _traceDictionary[messageLevel]
                .ExitMethod(leftMessage, rightMessage);
            }
            catch (ArgumentOutOfRangeException) { }
        }
Exemplo n.º 7
0
 static public void Write(MessageLevelEnum _level, string _tag, string _message)
 {
     foreach (Logger log in _List)
     {
         log.Write(_level, _tag, _message);
     }
 }
 /// <inheritdoc />
 public void SendDump(
     string leftMessage,
     string shortTitle,
     byte[] address,
     int count,
     MessageLevelEnum messageLevel = MessageLevelEnum.Debug)
 {
 }
Exemplo n.º 9
0
 public void Write(MessageLevelEnum _level, string _tag, string _message)
 {
     if (!ShowPerLevel[(int)_level])
     {
         return;
     }
     InternalWrite(_level, _tag, _message);
 }
Exemplo n.º 10
0
 protected override void InternalWrite(MessageLevelEnum _level, string _tag, string _message)
 {
     using (StreamWriter writer = new StreamWriter(Filename, true))
     {
         WriteHeader(writer, _level, _tag);
         writer.WriteLine(_message);
     }
 }
Exemplo n.º 11
0
 public LogMessage(string _tag, string _message, MessageLevelEnum _level = MessageLevelEnum.Information)
 {
     Tag     = _tag;
     Message = _message;
     Time    = DateTime.Now;
     Color   = Color.Black;
     Level   = _level;
 }
 /// <inheritdoc />
 public void SendDumpToTraceWindow(
     string traceWindowKey,
     string leftMessage,
     string shortTitle,
     byte[] memoryDump,
     short count,
     MessageLevelEnum messageLevel = MessageLevelEnum.Debug)
 {
 }
Exemplo n.º 13
0
 public LanguageChangedMessage(
     [JetBrains.Annotations.NotNull] object source,
     LanguageEnum payload,
     [JetBrains.Annotations.NotNull] string message,
     MessageLevelEnum messageLevel        = MessageLevelEnum.Verbose,
     [CallerFilePath] string callerFile   = null,
     [CallerMemberName] string methodName = null,
     [CallerLineNumber] int lineNumber    = 0) : base(source, payload, message, messageLevel, callerFile, methodName, lineNumber)
 {
 }
Exemplo n.º 14
0
        void WriteHeader(StreamWriter _writer, MessageLevelEnum _level, string _tag)
        {
            string header = "[ " + _level.ToString();

            if (!String.IsNullOrEmpty(_tag))
            {
                header += ", " + _tag;
            }
            if (_WriteEllapsedTime)
            {
                TimeSpan ts = DateTime.Now - _StartTime;
                header += ", " + ts.ToString(@"hh\:mm\:ss\.ff");
            }
            _writer.WriteLine(header + " ]");
        }
        ///  <summary>
        ///      Constructor.
        ///  </summary>
        /// <param name="source">       Source for the. </param>
        /// <param name="payload">      The payload. </param>
        /// <param name="message">      The message. </param>
        /// <param name="messageLevel"> The message level. </param>
        /// <param name="callerFile">   The caller file. </param>
        /// <param name="methodName">   Name of the method. </param>
        /// <param name="lineNumber">   The line number. </param>
        protected PayloadMessage(
            [NotNull] object source,
            [NotNull] T payload,
            [NotNull] string message,
            MessageLevelEnum messageLevel,
            string callerFile = null,
            string methodName = null,
            int lineNumber    = 0) : base(source, message, messageLevel, callerFile, methodName, lineNumber)
        {
            if (payload is null)
            {
                throw new ArgumentNullException(nameof(payload));
            }

            Payload = payload;
        }
Exemplo n.º 16
0
        /// <inheritdoc/>
        public void SendToTraceWindow <T>(
            string key,
            string leftMessage,
            T rightMessage,
            MessageLevelEnum messageLevel = MessageLevelEnum.Debug)
        {
            if (!IsEnabled)
            {
                return;
            }

            try
            {
                SendToTraceWindow(key, leftMessage, rightMessage.ToString(), messageLevel);
            }
            catch (ArgumentOutOfRangeException) { }
        }
Exemplo n.º 17
0
        /// <inheritdoc/>
        public void Log(
            string header,
            string message,
            MessageLevelEnum level,
            LoggingTargetEnum outputTarget = LoggingTargetEnum.LogFile | LoggingTargetEnum.TraceTool | LoggingTargetEnum.OutputPanel,
            bool shouldLogHeader           = true,
            bool isHeaderResourceKey       = false)
        {
            Debug.Assert(!string.IsNullOrWhiteSpace(header), DevConstants.ValueCannotBeNullOrWhitespace);
            Debug.Assert(!string.IsNullOrWhiteSpace(message), DevConstants.ValueCannotBeNullOrWhitespace);

            var logToOutputPanel = (outputTarget & LoggingTargetEnum.OutputPanel) == LoggingTargetEnum.OutputPanel;

            var messageToLog = message;

            if (shouldLogHeader || logToOutputPanel)
            {
                var headerToLog = isHeaderResourceKey ? _localisationService.GetLocalisedString(header) : header;

                if (shouldLogHeader)
                {
                    messageToLog = $"{headerToLog}: {message}";
                }

                if (logToOutputPanel)
                {
                    var watchLookup = new WatchLookup(headerToLog, message, _dateTimeService.Now, level);

                    var outputMessage = _messageFactory.CreateOutputMessage(this, watchLookup, messageLevel: level);
                    _messengerService.Send(outputMessage);
                }
            }

            if ((outputTarget & LoggingTargetEnum.LogFile) == LoggingTargetEnum.LogFile)
            {
                _logActionDictionary[level](messageToLog);
            }

            if (_traceService.IsEnabled && (outputTarget & LoggingTargetEnum.TraceTool) == LoggingTargetEnum.TraceTool)
            {
                _traceService.Send(messageToLog, level);
            }
        }
Exemplo n.º 18
0
        protected override void InternalWrite(MessageLevelEnum _level, string _tag, string _message)
        {
            string title = _level.ToString();

            if (!String.IsNullOrEmpty(_tag))
            {
                title += ", " + _tag;
            }
            MessageBoxIcon icon = MessageBoxIcon.Warning;

            if (_level == MessageLevelEnum.Error || _level == MessageLevelEnum.FatalError)
            {
                icon = MessageBoxIcon.Error;
            }
            else if (_level == MessageLevelEnum.Information)
            {
                icon = MessageBoxIcon.Information;
            }
            MessageBox.Show(_message, title, MessageBoxButtons.OK, icon);
        }
Exemplo n.º 19
0
        /// <summary>
        ///     Constructor.
        /// </summary>
        ///
        /// <exception cref="ArgumentException">    Thrown when one or more arguments have unsupported or illegal values. </exception>
        ///
        /// <param name="header">       The Message Header. This cannot be null or whitespace. </param>
        /// <param name="message">      The Message Contents. This cannot be null or whitespace. </param>
        /// <param name="time">         The Date/Time. </param>
        /// <param name="messageLevel"> The message level. </param>
        public WatchLookup(
            [JetBrains.Annotations.NotNull] string header,
            [JetBrains.Annotations.NotNull] string message,
            DateTime time,
            MessageLevelEnum messageLevel)
        {
            if (string.IsNullOrWhiteSpace(header))
            {
                throw new ArgumentException(DevConstants.ValueCannotBeNullOrWhitespace, nameof(header));
            }
            if (string.IsNullOrWhiteSpace(message))
            {
                throw new ArgumentException(DevConstants.ValueCannotBeNullOrWhitespace, nameof(message));
            }

            Header       = header;
            Message      = message;
            Time         = time;
            MessageLevel = messageLevel;
        }
Exemplo n.º 20
0
        /// <inheritdoc/>
        public void SendBackgroundColor(
            string leftMessage,
            int colour,
            MessageLevelEnum messageLevel = MessageLevelEnum.Debug)
        {
            if (!IsEnabled)
            {
                return;
            }

            if (string.IsNullOrWhiteSpace(leftMessage))
            {
                throw new ArgumentException(DevConstants.ValueCannotBeNullOrWhitespace, nameof(leftMessage));
            }

            try
            {
                _traceDictionary[messageLevel]
                .SendBackgroundColor(leftMessage, colour);
            }
            catch (ArgumentOutOfRangeException) { }
        }
Exemplo n.º 21
0
        /// <inheritdoc/>
        public void SendDumpToTraceWindow(
            string key,
            string leftMessage,
            string shortTitle,
            byte[] memoryDump,
            short count,
            MessageLevelEnum messageLevel = MessageLevelEnum.Debug)
        {
            if (!IsEnabled)
            {
                return;
            }

            if (string.IsNullOrWhiteSpace(key))
            {
                throw new ArgumentException(DevConstants.ValueCannotBeNullOrWhitespace, nameof(key));
            }
            if (string.IsNullOrWhiteSpace(leftMessage))
            {
                throw new ArgumentException(DevConstants.ValueCannotBeNullOrWhitespace, nameof(leftMessage));
            }
            if (string.IsNullOrWhiteSpace(shortTitle))
            {
                throw new ArgumentException(DevConstants.ValueCannotBeNullOrWhitespace, nameof(shortTitle));
            }

            if (_traceWindowDictionary.TryGetValue(key, out var traceWindow))
            {
                try
                {
                    _windowDictionary[messageLevel](traceWindow)
                    .SendDump(leftMessage, shortTitle, memoryDump, count);
                }
                catch (ArgumentOutOfRangeException) { }
            }
        }
Exemplo n.º 22
0
 protected override void InternalWrite(MessageLevelEnum _level, string _tag, string _message)
 {
     _Messages.Add(new LogMessage(_tag, _message, _level));
     SendChangedEvent();
 }
Exemplo n.º 23
0
 protected abstract void InternalWrite(MessageLevelEnum _level, string _tag, string _message);
 /// <inheritdoc />
 public void SendBackgroundColor(
     string leftMessage,
     int colour,
     MessageLevelEnum messageLevel = MessageLevelEnum.Debug)
 {
 }
 /// <inheritdoc />
 public void SendObject(
     string leftMessage,
     object rightObject,
     MessageLevelEnum messageLevel = MessageLevelEnum.Debug)
 {
 }
 /// <inheritdoc />
 public void Send(
     string leftMessage,
     string rightMessage,
     MessageLevelEnum messageLevel = MessageLevelEnum.Debug)
 {
 }
 /// <inheritdoc />
 public void ExitMethod(
     string leftMessage,
     MessageLevelEnum messageLevel = MessageLevelEnum.Debug)
 {
 }