forked from tianqiq/StaticHtml
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LogHelp.cs
54 lines (46 loc) · 1.27 KB
/
LogHelp.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Web;
namespace StaticHtml
{
static class LogHelp
{
readonly static TraceSwitch ts;
static LogHelp()
{
var lister = new TextWriterTraceListener(HttpRuntime.AppDomainAppPath + "staticHtml_log.txt");
lister.TraceOutputOptions = TraceOptions.DateTime;
Trace.Listeners.Add(lister);
Trace.AutoFlush = true;
ts = new TraceSwitch("staticHtml", "staticHtml 日志开关", "2");
}
public static void Write(string message)
{
Trace.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss") + ": " + message);
}
public static void Info(string message)
{
if (ts.TraceInfo)
{
Trace.TraceInformation(message);
}
}
public static void Warn(string message)
{
if (ts.TraceWarning)
{
Trace.TraceWarning(message);
}
}
public static void Error(string message)
{
if (ts.TraceError)
{
Trace.TraceError(message);
}
}
}
}