Menu

[r2]: / trunk / GoogleContactsSync / ILogger.cs  Maximize  Restore  History

Download this file

77 lines (64 with data), 2.1 kB

 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
using System;
using System.Collections.Generic;
using System.Text;
namespace WebGear.GoogleContactsSync
{
enum EventType
{
Information,
Warning,
Error
}
struct LogEntry
{
public DateTime date;
public EventType type;
public string msg;
public LogEntry(DateTime _date, EventType _type, string _msg)
{
date = _date; type = _type; msg = _msg;
}
}
class Logger
{
public List<LogEntry> messages = new List<LogEntry>();
public delegate void LogUpdatedHandler(string Message);
public event LogUpdatedHandler LogUpdated;
public Logger() {}
private string formatMessage(string message, EventType eventType)
{
return String.Format("{0}:{1}{2}", eventType, Environment.NewLine, message);
}
private string GetLogLine(LogEntry entry)
{
return String.Format("[{0} | {1}]\t{2}\r\n", entry.date, entry.type, entry.msg);
}
public void Log(string message, EventType eventType)
{
LogEntry new_logEntry = new LogEntry(DateTime.Now, eventType, message);
messages.Add(new_logEntry);
LogUpdated(GetLogLine(new_logEntry));
}
/*
public void LogUnique(string message, EventType eventType)
{
string logMessage = formatMessage(message, eventType);
if (!messages.ContainsValue(logMessage))
messages.Add(DateTime.Now, logMessage); //TODO: Outdated, no dictionary used anymore.
}
*/
public void ClearLog()
{
messages.Clear();
}
/*
public string GetText()
{
StringBuilder output = new StringBuilder();
foreach (var logitem in messages)
output.AppendLine(GetLogLine(logitem));
return output.ToString();
}
*/
}
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.