Ejemplo n.º 1
0
        public static void LogToFile(string logStr, bool noLineBreak, string filename)
        {
            if (string.IsNullOrWhiteSpace(filename))
            {
                filename = defaultLogName;
            }

            if (Path.GetExtension(filename) != ".txt")
            {
                filename = Path.ChangeExtension(filename, "txt");
            }
            file   = Path.Combine(Paths.GetLogPath(), filename);
            logStr = logStr.Replace(Environment.NewLine, " ").TrimWhitespaces();
            string time = DT.Now.Month + "-" + DT.Now.Day + "-" + DT.Now.Year + " " + DT.Now.Hour + ":" + DT.Now.Minute + ":" + DT.Now.Second;

            try
            {
                if (!noLineBreak)
                {
                    File.AppendAllText(file, $"{Environment.NewLine}[{id}] [{time}]: {logStr}");
                }
                else
                {
                    File.AppendAllText(file, " " + logStr);
                }
                id++;
            }
            catch
            {
                // this if fine, i forgot why
            }
        }
Ejemplo n.º 2
0
        public static void WriteToFile(string content, bool append, string filename)
        {
            if (string.IsNullOrWhiteSpace(filename))
            {
                filename = defaultLogName;
            }

            if (Path.GetExtension(filename) != ".txt")
            {
                filename = Path.ChangeExtension(filename, "txt");
            }

            file = Path.Combine(Paths.GetLogPath(), filename);

            string time = DT.Now.Month + "-" + DT.Now.Day + "-" + DT.Now.Year + " " + DT.Now.Hour + ":" + DT.Now.Minute + ":" + DT.Now.Second;

            try
            {
                if (append)
                {
                    File.AppendAllText(file, Environment.NewLine + time + ":" + Environment.NewLine + content);
                }
                else
                {
                    File.WriteAllText(file, Environment.NewLine + time + ":" + Environment.NewLine + content);
                }
            }
            catch
            {
            }
        }