-
Notifications
You must be signed in to change notification settings - Fork 0
/
Logging.cs
60 lines (50 loc) · 1.61 KB
/
Logging.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
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AdUserManager
{
class Logging
{
private static EventLog eventLog;
private static bool enabled;
public static void init()
{
enabled = Properties.Settings.Default.logging_enabled;
if (!enabled)
return;
eventLog = new EventLog("Application");
eventLog.Source = "AdUserManager";
if (!EventLog.SourceExists("AdUserManager"))
{
try
{
EventLog.CreateEventSource("AdUserManager", "Application");
// TODO messagebox("eventlog source created");
}
catch (Exception ex)
{
enabled = false;
throw new ApplicationException("Event log source could not be created. Try running as admin once to create the source. Exception: " + ex.Message);
}
}
}
public static void logInfo(string message)
{
if (enabled)
eventLog.WriteEntry(message, EventLogEntryType.Information);
}
public static void logWarning(string message)
{
if (enabled)
eventLog.WriteEntry(message, EventLogEntryType.Warning);
}
public static void logError(string message)
{
if (enabled)
eventLog.WriteEntry(message, EventLogEntryType.Error);
}
}
}