-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLogWriter.cs
More file actions
78 lines (66 loc) · 1.6 KB
/
LogWriter.cs
File metadata and controls
78 lines (66 loc) · 1.6 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.IO;
namespace TDMEngine
{
static class LogWriter
{
static string _logFileName = string.Empty;
public static string GetLogFileName()
{
return _logFileName;
}
public static void Init(string logFileName)
{
try
{
_logFileName = logFileName;
if (File.Exists(_logFileName))
{
//string newLog = Path.GetDirectoryName(_logFileName) + @"\" +
//Path.GetFileNameWithoutExtension(_logFileName) + DateTime.Now.ToString("dd-MM-yy-hh-mm-ss-fff") + ".txt";
//File.Move(_logFileName, newLog);
File.Delete(_logFileName);
}
LogIt("TDMEngine Started..\r\n",true);
}
catch (Exception exp)
{
LogIt("!!Warning!!Unable to create log file at the requested path." + exp.Message);
}
}
public static void ShowLog()
{
if (File.Exists(_logFileName))
{
ProcessStartInfo pStartInfo = new ProcessStartInfo();
pStartInfo.FileName = _logFileName;
Process process = new Process();
process.StartInfo = pStartInfo;
process.Start();
}
}
public static void LogIt( string message , bool timestamp=false)
{
try
{
StreamWriter writer = new StreamWriter(_logFileName, true);
if (timestamp )
message = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss.fff") + "\t" + message ;
writer.WriteLine(message);
writer.Close();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
public static void LogError(string message)
{
LogIt("!!Error!!: " + message);
}
}
}