time format
This commit is contained in:
parent
406e88987d
commit
fc1ec1401d
@ -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());
|
||||
|
||||
@ -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");
|
||||
}
|
||||
}
|
||||
12
DTLib/MyTimeFormat.cs
Normal file
12
DTLib/MyTimeFormat.cs
Normal file
@ -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();
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user