forked from w5xd/Digi-Rite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLogFile.cs
53 lines (45 loc) · 1.27 KB
/
LogFile.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace DigiRite
{
public class LogFile : IDisposable
{
public LogFile(String LogPath, bool append = true)
{
startlog(LogPath, append);
}
private void startlog(String LogPath, bool append)
{
logFile = new StreamWriter(LogPath, append);
logFile.WriteLine(String.Format("{0:yyyy/MM/dd HH:mm:ss}", DateTime.UtcNow));
}
public static long LogFileLength(String LogPath)
{
var fi = new FileInfo(LogPath);
fi.Refresh();
return fi.Length;
}
public void SendToLog(String s)
{
logFile.Write(String.Format("{0:HH:mm:ss} ", DateTime.UtcNow));
logFile.WriteLine(s);
}
public void Flush()
{ logFile.Flush(); }
public void ResetToEmpty(String LogPath)
{
if (logFile != null)
logFile.Dispose();
System.IO.File.Delete(LogPath);
startlog(LogPath, false);
}
public void Dispose()
{
((IDisposable)logFile).Dispose();
}
private System.IO.StreamWriter logFile;
}
}