Beispiel #1
0
        public void LogMessage(JobMessage message)
        {
            if (message.getMessage().Length == 0)
            {
                return;
            }

            if (!(message.IsAnError() && _logError) && !(message.IsAWarning() && _logWarning) && !(message.IsAMessage() && _logMessage))
            {
                return;
            }

            if (_logToDatabase)
            {
                LogToDataBase(message);
            }

            if (_logToFile)
            {
                LogToFile(message);
            }

            if (_logToConsole)
            {
                LogToConsole(message);
            }
        }
Beispiel #2
0
        private void LogToDataBase(JobMessage message)
        {
            string conectionString = ConfigurationManager.ConnectionStrings["TestDB"].ConnectionString;

            SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["TestDB"].ConnectionString);

            connection.Open();

            int messageType;

            if (message.IsAMessage())
            {
                messageType = 1;
            }
            else if (message.IsAnError())
            {
                messageType = 2;
            }
            else
            {
                messageType = 3;
            }

            string query = "INSERT INTO LOG VALUES('" + message.getMessage() + "', " + messageType.ToString() + ")";

            SqlCommand command = new SqlCommand(query, connection);

            command.ExecuteNonQuery();
        }
Beispiel #3
0
        private void LogToConsole(JobMessage message)
        {
            if (message.IsAnError())
            {
                Console.ForegroundColor = ConsoleColor.Red;
            }
            else if (message.IsAWarning())
            {
                Console.ForegroundColor = ConsoleColor.Yellow;
            }
            else if (message.IsAMessage())
            {
                Console.ForegroundColor = ConsoleColor.White;
            }

            Console.WriteLine(DateTime.Now.ToShortDateString() + " | " + DateTime.Now.ToLongTimeString() + " : " + message.getMessage());
        }