-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogfile.cs
62 lines (57 loc) · 1.5 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
54
55
56
57
58
59
60
61
62
using System;
#if DEBUG
using System.IO;
using System.Diagnostics;
using System.Windows.Forms;
#endif
namespace nwn2_Chatter
{
public static class logfile
{
#if DEBUG
const string Logfile = "logfile.txt";
#endif
/// <summary>
/// Creates <c><see cref="Logfile"/></c> (overwrites the previous logfile if it exists).
/// </summary>
public static void CreateLog()
{
#if DEBUG
string pfe = Path.Combine(Application.StartupPath, Logfile);
// string pfe = Path.Combine(Application.StartupPath, "logfile" + System.Diagnostics.Process.GetCurrentProcess().Id + ".txt");
using (var sw = new StreamWriter(File.Open(pfe,
FileMode.Create,
FileAccess.Write,
FileShare.None)))
{}
#endif
}
/// <summary>
/// Appends a line to <c><see cref="Logfile"/></c>.
/// </summary>
/// <param name="line">the line to write</param>
public static void Log(string line = "")
{
#if DEBUG
string pfe = Path.Combine(Application.StartupPath, Logfile);
// string pfe = Path.Combine(Application.StartupPath, "logfile" + System.Diagnostics.Process.GetCurrentProcess().Id + ".txt");
using (var sw = new StreamWriter(File.Open(pfe,
FileMode.Append,
FileAccess.Write,
FileShare.None)))
{
sw.WriteLine(line);
}
#endif
}
/// <summary>
/// Writes a stacktrace to <c><see cref="Logfile"/></c>.
/// </summary>
public static void Logtrace()
{
#if DEBUG
Log(new StackTrace().ToString());
#endif
}
}
}