forked from plenteum/plenteum-wallet-winforms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Logging.cs
46 lines (40 loc) · 1.16 KB
/
Logging.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
using System;
using System.IO;
using System.Windows.Forms;
namespace PlenteumWallet
{
public abstract class LogBase
{
protected readonly object lockObj = new object();
public abstract void Log(object obj, string message);
}
public class FileLogger : LogBase
{
public readonly string filePath = "ple.log";
public override void Log(object obj, string message)
{
lock (lockObj)
{
using (StreamWriter streamWriter = new StreamWriter(filePath))
{
streamWriter.WriteLine("[" + DateTime.Now.ToString() + "] - " + message);
streamWriter.Close();
}
}
}
}
public class WindowLogger : LogBase
{
public override void Log(object obj,string message)
{
lock (lockObj)
{
System.Windows.Forms.TextBox tb = (System.Windows.Forms.TextBox)obj;
tb.BeginInvoke((MethodInvoker)delegate ()
{
tb.AppendText(message + Environment.NewLine);
});
}
}
}
}