Beispiel #1
0
        public void LogMessage(MessageType messageType, string message)
        {
            var allowedLevels = _levelLogger.GetAllowedLevels();

            if (allowedLevels.Contains(messageType))
            {
                _databaseLoggerHelper.SaveLog(messageType, message);
            }
            else
            {
                throw new MessageTypeNotAllowedException($"Message type: {messageType} is not allowed, please enable it in the settings file.");
            }
        }
Beispiel #2
0
        public void LogMessage(MessageType messageType, string message)
        {
            Console.ForegroundColor = ConsoleColor.Blue;

            var allowedLevels = _levelLogger.GetAllowedLevels();

            if (allowedLevels.Contains(messageType))
            {
                Console.WriteLine($"Date: {DateTime.Now:dd/MM/yyy hh:mm}, MessageType: {messageType}, Message: {message}");
            }
            else
            {
                throw new MessageTypeNotAllowedException($"Message type: {messageType} is not allowed, please enable it in the settings file.");
            }
        }
Beispiel #3
0
        public void LogMessage(MessageType messageType, string message)
        {
            var allowedLevels = _levelLogger.GetAllowedLevels();

            if (allowedLevels.Contains(messageType))
            {
                var filePath = $"{Path}/{DateTime.Now:yyyyMMdd}.log";

                using (var sw = new StreamWriter(filePath, true))
                {
                    sw.WriteLine($"Date: {DateTime.Now}, MessageType: {messageType}, Message: {message}");

                    #region consoleMessage
                    Console.ForegroundColor = ConsoleColor.Blue;
                    Console.WriteLine($"Message was added to the file: {filePath}");
                    #endregion
                }
            }
            else
            {
                throw new MessageTypeNotAllowedException($"Message type: {messageType} is not allowed, please enable it in the settings file.");
            }
        }