namespace SendNotify
{
    internal class Log
    {
        public static void Logger(string str)
        {
            string outdir = Environment.CurrentDirectory + @"\logs\";
            if (!Directory.Exists(outdir)) Directory.CreateDirectory(outdir);
            string filename = $"{DateTime.Now.Day}_{DateTime.Now.Month}_{DateTime.Now.Year}_SendNotify";

            foreach (FileInfo file in new DirectoryInfo(outdir).GetFiles())
            {
                if (Convert.ToDateTime(file.LastWriteTime) < DateTime.Now.AddDays(-30))
                    file.Delete();
            }

            using (FileStream aFile = new FileStream($@"{outdir}\{filename}.log", FileMode.Append, FileAccess.Write))
            using (StreamWriter sw = new StreamWriter(aFile))
            {
                sw.WriteLine(DateTime.Now + " - " + str);
            }
        }
    }
}
