Beispiel #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="type">Type of message Warning</param>
        /// <param name="message">Message string.</param>
        private void WriteLog(TypeMessage type, string message)
        {
            Console.ForegroundColor = GetConsoleColor(type);
            DateTime currentDateTime = DateTime.Now;
            string   currentDate     = currentDateTime.ToString(Common.Culture.DateFormat); //this replace ToShortDateString()
            string   logString       = String.Format("type: {0} | date: {1} | message: {2}", (int)type, currentDate, message);

            if (LOG_CONSOLE)
            {
                Console.WriteLine(logString);
            }

            if (LOG_FILE)
            {
                FileManager.LogFile file = new FileManager.LogFile();
                file.NewLog(currentDate, logString);
                if (!file.Success)
                {
                    throw new Exception("Error while executing file manager.");
                }
            }

            if (LOG_DATABASE)
            {
                Database.RemoteServer db = new Database.RemoteServer();
                db.NewLog((int)type, message, currentDateTime);
                if (!db.Success)
                {
                    throw new Exception("Error while executing database server.");
                }
            }
        }
Beispiel #2
0
 public void NewLog(int type, string message, DateTime datetime)
 {
     try
     {
         using (RemoteServer db = new RemoteServer())
         {
             Log newLog = new Log()
             {
                 message  = message,
                 type     = type,
                 datetime = datetime
             };
             db.Logs.InsertOnSubmit(newLog);
             db.SubmitChanges();
         }
         success = true;
     }
     catch
     {
         success = false;
     }
 }