I have a file to create log entries into a text file, but the datetime will not work, I have tried setting to Utcnow but to no luck
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; namespace ParticleFramework { static class Log { private static FileStream file; public static string dateTime = String.Format("{0:d/M/yyyy HH:mm:ss}", new DateTime()); public static string logFile; public static Boolean Initialize(string f) { logFile = f; if (logFile != "") { try { file = new FileStream(logFile, FileMode.Append); plainWrite(""); plainWrite(""); Info("Particle Server logging started..."); return true; } catch { return false; } } else { return false; } } public static void Info(string text) { text = "[" + dateTime + "] " + text; plainWrite(text); } public static void Error(string text) { text = "[ERROR]" + text; plainWrite(text); } private static void plainWrite(string text) { try { StreamWriter sw = new StreamWriter(file); sw.WriteLine(text); sw.Close(); file = new FileStream(logFile, FileMode.Append); } catch { } } } } [1/1/0001 00:00:00]
No matter how long the server runs, and how many lines are added to the log, the above datetime does not change.