-
Notifications
You must be signed in to change notification settings - Fork 0
/
Logger.cs
50 lines (42 loc) · 1.43 KB
/
Logger.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
using System;
using System.IO;
namespace SubtitlesRunner
{
internal class Logger
{
private string _logFilename;
private string LogFilename
{
get
{
return _logFilename ?? (_logFilename = Path.Combine(Path.GetTempPath(), "SubtitlesRunner.log"));
}
}
private static string Timestamp
{
get
{
var now = DateTime.Now;
return now.ToLongDateString() + " " + now.ToLongTimeString();
}
}
public bool IsDebugMode { get { return AppStartupOptions.DebugMode; } }
public void Debug(string s, params object[] parameters)
{
if (!IsDebugMode) return;
File.AppendAllText(LogFilename, Timestamp + @" DEBUG: " + string.Format(s, parameters) + Environment.NewLine);
}
public void Error(string s, params object[] parameters)
{
File.AppendAllText(LogFilename, Timestamp + @" ERROR: " + string.Format(s, parameters) + Environment.NewLine);
}
public void Exception(Exception exception, string s, params object[] parameters)
{
File.AppendAllText(LogFilename, Timestamp + @" ERROR: " + string.Format(s, parameters) + Environment.NewLine + exception + Environment.NewLine);
}
public void Clear()
{
File.Delete(LogFilename);
}
}
}