Exemplo n.º 1
0
        public void TestLogDataBase()
        {
            var kindOfLogs = new KindOfLogs();

            kindOfLogs.LogToDatabase = true;
            Assert.IsTrue(JobLogger.LogMessage("mensaje", KindOfError.Error, kindOfLogs));
        }
Exemplo n.º 2
0
        public void TestEmptyMessage()
        {
            var kindOfLogs = new KindOfLogs();

            kindOfLogs.LogToConsole = true;
            Assert.IsFalse(JobLogger.LogMessage("   ", KindOfError.Error, kindOfLogs));
        }
Exemplo n.º 3
0
        public static bool LogMessage(string message, KindOfError error, KindOfLogs log)
        {
            try
            {
                InstanceServices();
                message = message.Trim();

                if (message == string.Empty)
                {
                    return(false);
                }

                if (!log.LogToConsole && !log.LogToFile && !log.LogToDatabase)
                {
                    throw new Exception("Invalid configuration");
                }

                if (log.LogToDatabase)
                {
                    _dataBaseLogServices.LogError(message, error);
                }

                if (log.LogToFile)
                {
                    _fileLogServices.LogError(message);
                }

                if (log.LogToConsole)
                {
                    _consoleLogServices.LogError(message, error);
                }

                return(true);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(false);
            }
        }