-
Notifications
You must be signed in to change notification settings - Fork 0
/
Log.Windows.cs
33 lines (27 loc) · 1 KB
/
Log.Windows.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
using System;
using System.Diagnostics;
namespace MastodonGitHubBot;
internal partial class Log : IDisposable
{
private const string LogName = "MastodonGitHubBot";
private const string LogSource = LogName;
private const string LogMachineName = ".";
private readonly EventLog _eventLog;
public Log()
{
// Throws if non-elevated due to attempt to read "Security" source.
if (!EventLog.SourceExists(LogSource, LogMachineName))
{
EventLog.CreateEventSource(new EventSourceCreationData(LogSource, LogName) { MachineName = LogMachineName });
}
_eventLog = new EventLog(LogName, LogMachineName, LogSource);
}
public void Dispose() => _eventLog.Dispose();
private void WriteInternal(string message, LogType type)
{
Validate(message, type);
ConsoleWrite(message, type);
// Throws if non-elevated due to attempt to read "Security" source.
_eventLog.WriteEntry(message, (EventLogEntryType)type);
}
}