From fc1ec1401dcbeca971b2d66a22b89edb4743facb Mon Sep 17 00:00:00 2001 From: timerix Date: Wed, 17 Aug 2022 03:59:40 +0600 Subject: [PATCH] time format --- DTLib/Logging/FileLogger.cs | 9 ++++----- DTLib/Logging/Tester.cs | 2 +- DTLib/MyTimeFormat.cs | 12 ++++++++++++ 3 files changed, 17 insertions(+), 6 deletions(-) create mode 100644 DTLib/MyTimeFormat.cs diff --git a/DTLib/Logging/FileLogger.cs b/DTLib/Logging/FileLogger.cs index 2e8e374..f012a22 100644 --- a/DTLib/Logging/FileLogger.cs +++ b/DTLib/Logging/FileLogger.cs @@ -6,15 +6,14 @@ public class FileLogger : IDisposable { public FileLogger(string logfile) { - LogfilePath = logfile; + LogfileName = logfile; LogfileStream = File.OpenAppend(logfile); } public FileLogger(string dir, string programName) - : this($"{dir}{Путь.Разд}{programName}_{DateTime.Now.ToString(CultureInfo.InvariantCulture)}.log" - .Replace(':', '-').Replace(' ', '_')) { } + : this($"{dir}{Путь.Разд}{programName}_{DateTime.Now.ToString(MyTimeFormat.Instance)}.log") { } - public string LogfilePath { get; protected set; } + public string LogfileName { get; protected set; } public System.IO.FileStream LogfileStream { get; protected set; } protected string LastLogMessageTime; @@ -23,7 +22,7 @@ public class FileLogger : IDisposable { lock (LogfileStream) { - LastLogMessageTime = DateTime.Now.ToString(CultureInfo.InvariantCulture); + LastLogMessageTime = DateTime.Now.ToString(MyTimeFormat.Instance); LogfileStream.WriteByte('['.ToByte()); LogfileStream.Write(LastLogMessageTime.ToBytes()); LogfileStream.Write("]: ".ToBytes()); diff --git a/DTLib/Logging/Tester.cs b/DTLib/Logging/Tester.cs index 6f12c28..ce7e99d 100644 --- a/DTLib/Logging/Tester.cs +++ b/DTLib/Logging/Tester.cs @@ -13,6 +13,6 @@ public static class Tester operation(); clock.Stop(); double time=(double)(clock.ElapsedTicks)/Stopwatch.Frequency/repeats; - Log("y",$"operation ","b",op_name,"y"," lasted ","b",time.ToString(CultureInfo.InvariantCulture),"y"," seconds"); + Log("y",$"operation ","b",op_name,"y"," lasted ","b",time.ToString(MyTimeFormat.Instance),"y"," seconds"); } } \ No newline at end of file diff --git a/DTLib/MyTimeFormat.cs b/DTLib/MyTimeFormat.cs new file mode 100644 index 0000000..677db5b --- /dev/null +++ b/DTLib/MyTimeFormat.cs @@ -0,0 +1,12 @@ +namespace DTLib; + +public class MyTimeFormat : IFormatProvider +{ + public static MyTimeFormat Instance=new(); + public object GetFormat(Type formatType) + { + if(formatType==typeof(DateTime)) + return "yyyy-MM-dd_HH-mm-ss+zz"; + else throw new FormatException(); + } +} \ No newline at end of file