-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathLog.cs
84 lines (67 loc) · 2.04 KB
/
Log.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// -----------------------------------------------------------------------
// <copyright file="Log.cs" company="">
// Triangle.NET code by Christian Woltering, http://triangle.codeplex.com/
// </copyright>
// -----------------------------------------------------------------------
namespace TriangleNet
{
using System.Collections.Generic;
using TriangleNet.Logging;
/// <summary>
/// A simple logger, which logs messages to a List.
/// </summary>
/// <remarks>Using singleton pattern as proposed by Jon Skeet.
/// http://csharpindepth.com/Articles/General/Singleton.aspx
/// </remarks>
public sealed class Log : ILog<LogItem>
{
/// <summary>
/// Log detailed information.
/// </summary>
public static bool Verbose { get; set; }
private List<LogItem> log = new List<LogItem>();
private LogLevel level = LogLevel.Info;
#region Singleton pattern
private static readonly Log instance = new Log();
// Explicit static constructor to tell C# compiler
// not to mark type as beforefieldinit
static Log() { }
private Log() { }
public static ILog<LogItem> Instance
{
get
{
return instance;
}
}
#endregion
public void Add(LogItem item)
{
log.Add(item);
}
public void Clear()
{
log.Clear();
}
public void Info(string message)
{
log.Add(new LogItem(LogLevel.Info, message));
}
public void Warning(string message, string location)
{
log.Add(new LogItem(LogLevel.Warning, message, location));
}
public void Error(string message, string location)
{
log.Add(new LogItem(LogLevel.Error, message, location));
}
public IList<LogItem> Data
{
get { return log; }
}
public LogLevel Level
{
get { return level; }
}
}
}