-
Notifications
You must be signed in to change notification settings - Fork 0
/
UccLogWatcher.cs
56 lines (48 loc) · 1.63 KB
/
UccLogWatcher.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Windows.Forms;
namespace Netgao.Telephony.Workflow
{
public sealed class UccLogWatcher : StreamWriter
{
public static readonly TextWriter Watcher = Synchronized(new UccLogWatcher());
static UccLogWatcher()
{
AppDomain.CurrentDomain.ProcessExit += (sender, e) => Watcher.Close();
AppDomain.CurrentDomain.DomainUnload += (sender, e) => Watcher.Close();
}
public UccLogWatcher()
: base(GetLogFileName(), true)
{
}
public static void Error(string message)
{
Watcher.WriteLine("{0} > {1}", DateTime.Now, message);
Watcher.Flush();
}
public static void Error(string message, Exception ex)
{
Watcher.WriteLine("{0} > {1}", DateTime.Now, ex.Message);
Watcher.Flush();
}
public static void Trace(string format, params object[] args)
{
if (System.Environment.UserInteractive)
{
Watcher.WriteLine("{0} > {1}", DateTime.Now, String.Format(format, args));
Watcher.Flush();
}
else
{
Watcher.WriteLine("{0} > {1}", DateTime.Now, String.Format(format, args));
Watcher.Flush();
}
}
private static string GetLogFileName()
{
return String.Format(@"{0}\logs\server-log-{1}.log", Path.GetDirectoryName(Application.ExecutablePath), DateTime.Now.ToString("yyyyMMdd"));
}
}
}