Exemplo n.º 1
0
 public Log_Object(Log_Type _type, DateTime dt_log, string _title, string _msg, bool is_LogTime_HaveDate)
 {
     Log_type = _type;
     Time_Log = (is_LogTime_HaveDate) ? dt_log.ToString(Time_Format_Long) : dt_log.ToString(Time_Format_Short);
     Title    = _title;
     Msg      = _msg;
 }
Exemplo n.º 2
0
 private static void Output(Log_Type type, string msg)
 {
     if (null != OnOutput)
     {
         OnOutput(type, msg);
     }
 }
Exemplo n.º 3
0
        public static void Log(Log_Type type, string text)
        {
            if (!_active)
            {
                return;
            }
            string begin = "";

            switch (type)
            {
            case Log_Type.ERROR:
                begin = "<span style=\"color: #00f000;\">";
                break;

            case Log_Type.INFO:
                begin = "<span style=\"color: #0008f0;\">";
                break;

            case Log_Type.WARNING:
                begin = "<span style=\"color: #00ff00;\">";
                break;
            }
            text = begin + DateTime.Now.ToLongTimeString() + " : " + text + "</span><br>";
            Output(text);
        }
Exemplo n.º 4
0
        public static void Log(Log_Type type, params string[] text)
        {
            if (!_active)
            {
                return;
            }

            var begin = "";

            switch (type)
            {
            case Log_Type.ERROR:
                begin = "<span style=\"color: #00f000;\">";
                break;

            case Log_Type.INFO:
            default:
                begin = "<span style=\"color: #0008f0;\">";
                break;

            case Log_Type.WARNING:
                begin = "<span style=\"color: #00ff00;\">";
                break;
            }

            var concatText = text.Aggregate("", (output, t) => output + "<li>" + SecurityElement.Escape(t) + "</li>");

            Output(begin + DateTime.Now.ToUniversalTime().ToLongTimeString() + " : <ol>" + concatText + "</ol></span><br>");
        }
Exemplo n.º 5
0
        public static void Write_Log(Log_Type _type, string _title, string _msg)
        {
            Log_Object log = new Log_Object(_type, DateTime.Now, _title, _msg, false);

            string str_log = log.Print(true);

            Console.WriteLine(str_log);

            try
            {
                try
                {
                    if (Monitor.TryEnter(Locker, 500))
                    {
                        using (StreamWriter sw = new StreamWriter(_Log_Full_Path, true, _Log_Encoding))
                        {
                            sw.WriteLine(str_log);
                        }
                    }
                }
                finally
                {
                    Monitor.Exit(Locker);
                }
            }
            catch (Exception ex)
            {
                //MessageBox.Show(ex.ToString());
            }
        }
Exemplo n.º 6
0
 private static void Output(Log_Type type, ConsoleColor cc, string msg)
 {
     if (null != OnOutputWithConsoleColor)
     {
         OnOutputWithConsoleColor(type, cc, msg);
     }
 }
Exemplo n.º 7
0
        public static void Write(string module, Log_Type log_type, string log_message)
        {
            //File operations sometimes go wrong.As a result i used loop for try again
            //You can set parameter Log_Directory in Write method or open a variable in Settings (Properties.Settings.Default.Log_Directory)
            //I used StringBuilder for use Ram efficiently
            string directory = "";
            string file_name = "";

            for (int i = 0; i < 5; i++)
            {
                try
                {
                    StringBuilder stringBuilder = new StringBuilder();
                    if (Properties.Settings.Default.Log_Directory.Equals(""))
                    {
                        stringBuilder.Append(Directory.GetCurrentDirectory());
                        stringBuilder.Append("\\Log");
                        directory     = stringBuilder.ToString();
                        stringBuilder = new StringBuilder();
                    }
                    else
                    {
                        directory = Properties.Settings.Default.Log_Directory;
                    }

                    stringBuilder.Append(System.Reflection.Assembly.GetEntryAssembly().GetName().Name);
                    stringBuilder.Append(DateTime.Now.ToString("yyyyMMdd"));
                    stringBuilder.Append(".log");
                    file_name     = stringBuilder.ToString();
                    stringBuilder = new StringBuilder();

                    if (!Directory.Exists(directory))
                    {
                        Directory.CreateDirectory(directory);
                    }
                    StreamWriter file;

                    stringBuilder.Append(directory);
                    stringBuilder.Append("\\");
                    stringBuilder.Append(file_name);
                    file          = File.AppendText(stringBuilder.ToString());
                    stringBuilder = new StringBuilder();

                    stringBuilder.Append(DateTime.Now.ToString());
                    stringBuilder.Append("      ");
                    stringBuilder.Append(module);
                    stringBuilder.Append("      ");
                    stringBuilder.Append(log_type.ToString());
                    stringBuilder.Append("      ");
                    stringBuilder.Append(log_message);
                    file.WriteLine(stringBuilder.ToString());
                    file.Close();
                    break;
                }
                catch
                {
                }
            }
        }
Exemplo n.º 8
0
 /// <summary>
 /// Force flush all loggers of a specific type.
 /// </summary>
 /// <param name="log_type"></param>
 public static void Flush(Log_Type log_type)
 {
     foreach (Logger logger in logger_list)
     {
         if (logger.GetType().Equals(Get_Type(log_type)))
         {
             logger.Flush();
         }
     }
 }
Exemplo n.º 9
0
        /// <summary>
        /// Return the Class Type object from the log_type enum.
        /// </summary>
        /// <param name="log_type"></param>
        /// <returns></returns>
        private static Type Get_Type(Log_Type log_type)
        {
            switch (log_type)
            {
            case Log_Type.File_Logger:
                return(typeof(File_Logger));

            default:
                return(null);
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Add a new logging system. Logging systems can be used concurrently.
        /// </summary>
        /// <param name="logger"></param>
        public static void Add_Logger(Log_Type log_type)
        {
            switch (log_type)
            {
            case Log_Type.File_Logger:
                logger_list.Add(new File_Logger());
                break;

            default:
                break;
            }
        }
Exemplo n.º 11
0
 public static void log(Log_Type type, string text)
 {
     #if WINDOWS
         if (!_active) return;
         string begin = "";
         switch (type)
         {
             case Log_Type.ERROR: begin = "<span style=\"color: #00f000;\"><br/>"; break;
             case Log_Type.INFO: begin = "<span style=\"color: #0008f0;\"><br/>"; break;
             case Log_Type.WARNING: begin = "<span style=\"color: #00ff00;\"><br/>"; break;
         }
         text = begin+System.DateTime.Now.ToLongTimeString() + " : " + text + "</span>";
         Output(text);
     #endif
 }
Exemplo n.º 12
0
    static void LogMessage(Type Class, string Message, Log_Type Type)
    {
        string FullMessage = "(CLASS : " + Class.ToString() + ") [" + Type.ToString().ToUpper() + "]: " + Message;

        if (Mode == Log_Mode.File || Mode == Log_Mode.Mixed)
        {
            //LogToFile(FullMessage);
            TOFILE(Class, Type, FullMessage);
        }

        if (Mode == Log_Mode.Console || Mode == Log_Mode.Mixed)
        {
            UnityEngine.Debug.Log(FullMessage);
        }
    }
Exemplo n.º 13
0
    static void TOFILE(Type Class, Log_Type Type, string Message)
    {
        if (!Launched)
        {
            Launched = true;

            ClearLogs();
        }

        string[] Paths = new string[3];

        Paths[0] = "Main";

        switch (ModeFile)
        {
        case File_Mode.Single:
            break;

        case File_Mode.SpreadByClass:
            Paths[1] = "/SpreadByClass/" + Class;
            break;

        case File_Mode.SpreadByType:
            Paths[2] = "/SpreadByType/" + Type.ToString().ToLower();
            break;

        case File_Mode.All:
            Paths[1] = "/SpreadByClass/" + Class;
            Paths[2] = "/SpreadByType/" + Type.ToString().ToLower();
            break;

        default:
            break;
        }

        for (int i = 0; i < Paths.Length; i++)
        {
            if (Paths[i] != null)
            {
                FileUtils.AppendFile(BasePath + Paths[i] + ".log", Message, "|" + Paths[i] + ".log" + "|\n|====================|");
            }
        }
    }
Exemplo n.º 14
0
 private static void Output(Log_Type type, string msg)
 {
     if (null != OnOutput) {
     OnOutput(type, msg);
       }
 }
Exemplo n.º 15
0
 public static void log(Log_Type type, string text, Vector3 vector)
 {
     log(type, text + ": X:" + vector.X + " Y:" + vector.Y + " Z:" + vector.Z);
 }