forked from Geektoolkit/Dynaframe3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Logger.cs
61 lines (54 loc) · 1.91 KB
/
Logger.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
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.Collections.Specialized;
namespace Dynaframe3
{
static public class Logger
{
public static List<string> memoryLog = new List<string>();
static int MaxLogLength = 1000; // arbitrary for now
static public void LogComment(string comment)
{
// Note: Appsettings determins if this actually logs or not. Defaults to 'off'.
if (AppSettings.Default.EnableLogging)
{
string date = DateTime.Now.ToString("g");
string logComment = date + ":" + comment;
Console.WriteLine(logComment);
Debug.WriteLine(logComment);
memoryLog.Add(logComment);
if (memoryLog.Count > 1000)
{
memoryLog.RemoveRange(0, memoryLog.Count - MaxLogLength);
}
}
}
/// <summary>
/// Returns the log in a webpage friendly format. We can add color syntax in the future using this.
/// </summary>
/// <returns></returns>
public static string GetLogAsHTML()
{
// if disabled help the user out
if (!AppSettings.Default.EnableLogging)
{
return "Logging is currently disabled! Please enable logging to continue...";
}
string returnVal = "";
for (int i = memoryLog.Count - 1; i > 0; i--)
{
returnVal += memoryLog[i] + "\r\n";
}
return returnVal;
}
public static void LogNameValueCollection(NameValueCollection collection)
{
for (int i = 0; i < collection.Count; i++)
{
LogComment("Key: " + collection.Keys[i] + " Value: " + collection.GetValues(i).ToString());
}
}
}
}