-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLogWriter.cs
More file actions
52 lines (50 loc) · 1.34 KB
/
LogWriter.cs
File metadata and controls
52 lines (50 loc) · 1.34 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
using System;
using System.IO;
using System.Reflection;
public class LogWriter
{
private string m_exePath = string.Empty;
private string logName = string.Empty;
public LogWriter(string logMessage, string logName)
{
this.logName = logName;
LogWrite(logMessage);
}
public void LogWrite(string logMessage)
{
m_exePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string lgname = string.Empty;
if (!string.IsNullOrEmpty(this.logName))
{
lgname = logName;
}
else
{
lgname = "log";
}
try
{
using (StreamWriter w = File.AppendText(m_exePath + "\\" + lgname + ".txt"))
{
Log(logMessage, w);
}
}
catch (Exception ex)
{
throw new Exception("LogWriter class: " + ex.Message.ToString());
}
}
public void Log(string logMessage, TextWriter txtWriter)
{
try
{
txtWriter.Write("\r\nLog Entry : ");
txtWriter.Write("{0}", DateTime.Now.ToString("HH:mm:ss MM/dd/yyyy"));
txtWriter.Write(": [{0}]", logMessage);
}
catch (Exception ex)
{
throw new Exception("LogWriter class: " + ex.Message.ToString());
}
}
}