using System;
using System.IO;
namespace TurboBotNew
{
public static class Log
{
static string s_logFile = System.IO.Directory.GetCurrentDirectory() + "\\log.txt";
static int i_lastLog = 0;
public static void Write(string message)
{
string TimeNow = DateTime.Now.ToString("HH:mm:ss");
message = "[" + TimeNow + "] " + message + "\n";
File.AppendAllText(s_logFile, message);
}
public static void Close()
{
if (System.IO.File.Exists(s_logFile))
System.IO.File.Delete(s_logFile);
}
public static string Read(string s_log)
{
if (!System.IO.File.Exists(s_logFile))
Write("Создание лога");
var mass = System.IO.File.ReadAllLines(s_logFile);
string s_message = "";
for (int i = mass.Length - 1; i > i_lastLog; i--)
{
s_message = mass[i] + Environment.NewLine + s_message;
}
i_lastLog = mass.Length - 1;
return s_log + s_message;
}
}
}
s_message = mass[i] + Environment.NewLine + s_message;
- для таких вещей есть StringBuilder, который работает быстрее.s_message = string.Join(Environment.NewLine, mass)