forked from NCDyson/StudioCCS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Logger.cs
70 lines (62 loc) · 2.3 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
62
63
64
65
66
67
68
69
70
/*
* Created by SharpDevelop.
* User: NCDyson
* Date: 7/21/2017
* Time: 11:22 PM
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Drawing;
using System.Windows.Forms;
namespace StudioCCS
{
/// <summary>
/// Description of Logger.
/// </summary>
public static class Logger
{
private static Dictionary<int, bool> FiredWarnings = new Dictionary<int, bool>();
private static Dictionary<int, bool> FiredShots = new Dictionary<int, bool>();
public enum LogType {LogAll, LogOnceCode, LogOnceValue}
public static RichTextBox LogControl = null;
public static void SetLogControl(RichTextBox r)
{
LogControl = r;
}
public static void LogError(string errorText, LogType logAs = LogType.LogAll, [CallerMemberName] string callingMethod = "", [CallerLineNumber] int callingLine = 0)
{
LogGeneric(errorText, Color.DarkRed, logAs, callingMethod, callingLine);
}
public static void LogWarning(string warningText, LogType logAs = LogType.LogAll, [CallerMemberName] string callingMethod = "", [CallerLineNumber] int callingLine = 0)
{
LogGeneric(warningText, Color.Orange, logAs, callingMethod, callingLine);
}
public static void LogInfo(string infoText, LogType logAs = LogType.LogAll, [CallerMemberName] string callingMethod = "", [CallerLineNumber] int callingLine = 0)
{
LogGeneric(infoText, Color.White, logAs, callingMethod, callingLine);
}
private static void LogGeneric(string outputText, Color textColor, LogType logAs = LogType.LogAll, [CallerMemberName] string callingMethod = "", [CallerLineNumber] int callingLine = 0)
{
if(logAs == LogType.LogOnceCode)
{
int logDictKey = string.Format("{0}:{1}", callingMethod, callingLine).GetHashCode();
if(FiredWarnings.ContainsKey(logDictKey)) return;
FiredWarnings[logDictKey] = true;
}
else if(logAs == LogType.LogOnceValue)
{
int logTextKey = outputText.GetHashCode();
if(FiredShots.ContainsKey(logTextKey)) return;
FiredShots[logTextKey] = true;
}
if(LogControl == null) return;
Color oldColor = LogControl.SelectionColor;
LogControl.SelectionColor = textColor;
LogControl.AppendText(outputText);
LogControl.SelectionColor = oldColor;
}
}
}