forked from wakatime/visualstudio-wakatime
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Logger.cs
75 lines (59 loc) · 2.21 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
71
72
73
74
75
using System;
using System.Globalization;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
namespace WakaTime
{
internal enum LogLevel
{
Debug = 1,
Info,
Warning,
HandledException
};
static class Logger
{
private static IVsOutputWindowPane _wakatimeOutputWindowPane;
private static IVsOutputWindowPane WakatimeOutputWindowPane
{
get { return _wakatimeOutputWindowPane ?? (_wakatimeOutputWindowPane = GetWakatimeOutputWindowPane()); }
}
private static IVsOutputWindowPane GetWakatimeOutputWindowPane()
{
var outputWindow = Package.GetGlobalService(typeof(SVsOutputWindow)) as IVsOutputWindow;
if (outputWindow == null) return null;
var outputPaneGuid = new Guid(GuidList.GuidWakatimeOutputPane.ToByteArray());
IVsOutputWindowPane windowPane;
outputWindow.CreatePane(ref outputPaneGuid, "Wakatime", 1, 1);
outputWindow.GetPane(ref outputPaneGuid, out windowPane);
return windowPane;
}
internal static void Debug(string message)
{
if (!WakaTimePackage.Debug)
return;
Log(LogLevel.Debug, message);
}
internal static void Error(string message, Exception ex = null)
{
var exceptionMessage = string.Format("{0}: {1}", message, ex);
Log(LogLevel.HandledException, exceptionMessage);
}
internal static void Warning(string message)
{
Log(LogLevel.Warning, message);
}
internal static void Info(string message)
{
Log(LogLevel.Info, message);
}
private static void Log(LogLevel level, string message)
{
var outputWindowPane = WakatimeOutputWindowPane;
if (outputWindowPane == null) return;
var outputMessage = string.Format("[Wakatime {0} {1}] {2}{3}", Enum.GetName(level.GetType(), level),
DateTime.Now.ToString("hh:mm:ss tt", CultureInfo.InvariantCulture), message, Environment.NewLine);
outputWindowPane.OutputString(outputMessage);
}
}
}