2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Runtime.InteropServices;
6using System.Threading.Tasks;
15 private IntPtr eventLog = IntPtr.Zero;
38 : base(
"Windows Event Log")
42 this.eventLog =
Win32.RegisterEventSourceW(MachineName, Source);
43 if (this.eventLog == IntPtr.Zero)
45 this.eventLog =
Win32.RegisterEventSourceW(MachineName,
"Application");
46 if (this.eventLog == IntPtr.Zero)
47 throw new Win32Exception(Marshal.GetLastWin32Error());
50 catch (DllNotFoundException ex)
52 throw new PlatformNotSupportedException(
"Win32 APIs not found.", ex);
63 if (this.eventLog != IntPtr.Zero)
65 Win32.DeregisterEventSource(this.eventLog);
66 this.eventLog = IntPtr.Zero;
83 EventId = 0b11100000000000000000000000000000;
89 EventId = 0b10100000000000000000000000000000;
96 EventId = 0b01100000000000000000000000000000;
102 StringBuilder Message =
new StringBuilder(
Event.
Message);
103 Message.AppendLine();
104 Message.AppendLine();
106 Message.Append(
"Timestamp: ");
108 Message.Append(
"Type: ");
109 Message.AppendLine(
Event.
Type.ToString());
110 Message.Append(
"Level: ");
115 Message.Append(
"Event ID: ");
121 Message.Append(
"Object: ");
127 Message.Append(
"Object: ");
133 Message.Append(
"Actor: ");
139 Message.Append(
"Module: ");
145 Message.Append(
"Facility: ");
151 foreach (KeyValuePair<string, object> Tag
in Event.
Tags)
153 Message.AppendLine(Tag.Key);
154 Message.Append(
": ");
156 if (!(Tag.Value is
null))
157 Message.AppendLine(Tag.Value.ToString());
163 Message.AppendLine();
164 Message.AppendLine(
"Stack Trace:");
168 string s = Message.ToString();
169 List<string> Strings =
new List<string>();
177 Strings.Add(s.Substring(i, 30000));
182 Strings.Add(s.Substring(i));
187 if (!
Win32.ReportEventW(
this.eventLog, Type, 0, EventId, IntPtr.Zero, 1, 0, Strings.ToArray(), IntPtr.Zero))
188 throw new Win32Exception(Marshal.GetLastWin32Error());
190 return Task.CompletedTask;
Class representing an event.
string Message
Free-text event message.
EventType Type
Type of event.
string Object
Object related to the event.
EventLevel Level
Event Level.
string Actor
Actor responsible for the action causing the event.
string Module
Module where the event is reported.
DateTime Timestamp
Timestamp of event.
KeyValuePair< string, object >[] Tags
Variable set of tags providing event-specific information.
string EventId
Computer-readable Event ID identifying type of even.
string Facility
Facility can be either a facility in the network sense or in the system sense.
string StackTrace
Stack Trace of event.
Base class for event sinks.
Handles interaction with the Windows Event Log API.
Defines an event sink that logs incoming events to a Windows Event Log.
override void Dispose()
IDisposable.Dispose()
WindowsEventLog(string Source)
Defines an event sink that logs incoming events to a Windows Event Log.
override Task Queue(Event Event)
Queues an event to be output.
WindowsEventLog(string Source, string MachineName)
Defines an event sink that logs incoming events to a Windows Event Log.
WindowsEventType
Windows event type enumeration.