3using System.Security.Cryptography.X509Certificates;
6using System.Threading.Tasks;
20 private X509Certificate certificate;
21 private readonly SemaphoreSlim synchObj =
new SemaphoreSlim(1);
22 private readonly Uri callbackUrl;
23 private readonly
int maxSecondsUsed;
24 private readonly
int maxSecondsUnused;
25 private readonly
bool collectOnType;
26 private readonly
bool collectOnLevel;
27 private readonly
bool collectOnEventId;
28 private readonly
bool collectOnObject;
29 private readonly
bool collectOnActor;
30 private readonly
bool collectOnFacility;
31 private readonly
bool collectOnModule;
32 private readonly
bool collected;
51 X509Certificate Certificate)
52 : this(
ObjectID, CallbackUrl, Certificate, 0, 0, false, false,
53 false, false, false, false, false)
73 int MaxSecondsUsed,
int MaxSecondsUnused,
bool CollectOnType,
74 bool CollectOnLevel,
bool CollectOnEventId,
bool CollectOnObject,
75 bool CollectOnActor,
bool CollectOnFacility,
bool CollectOnModule)
78 if (MaxSecondsUsed < MaxSecondsUnused)
79 throw new ArgumentException(
"MaxSecondsUsed must be greater than, or equal to, MaxSecondsUnused.", nameof(MaxSecondsUsed));
81 this.collected = MaxSecondsUnused > 0;
82 this.callbackUrl =
new Uri(CallbackUrl);
83 this.certificate = Certificate;
84 this.maxSecondsUsed = MaxSecondsUsed;
85 this.maxSecondsUnused = MaxSecondsUnused;
86 this.collectOnType = CollectOnType;
87 this.collectOnLevel = CollectOnLevel;
88 this.collectOnEventId = CollectOnEventId;
89 this.collectOnObject = CollectOnObject;
90 this.collectOnActor = CollectOnActor;
91 this.collectOnFacility = CollectOnFacility;
92 this.collectOnModule = CollectOnModule;
97 TimeSpan.FromSeconds(
this.maxSecondsUsed),
98 TimeSpan.FromSeconds(
this.maxSecondsUnused));
100 this.eventCache.Removed += this.EventCache_Removed;
109 this.eventCache?.
Clear();
111 this.eventCache =
null;
113 return base.DisposeAsync();
122 this.certificate = Certificate;
131 Dictionary<string, object> Payload =
new Dictionary<string, object>()
134 {
"Type", Event.Type },
135 {
"Level", Event.Level },
136 {
"EventId", Event.EventId },
137 {
"Object", Event.Object },
138 {
"Actor", Event.Actor },
139 {
"Facility", Event.Facility },
140 {
"Module", Event.Module },
141 {
"Message", Event.Message },
142 {
"Tags", Event.Tags },
143 {
"StackTrace", Event.StackTrace }
148 await this.synchObj.WaitAsync();
151 StringBuilder sb =
new StringBuilder();
154 if (this.collectOnType)
155 Append(sb,
Event.
Type.ToString(), ref First);
157 if (this.collectOnLevel)
158 Append(sb,
Event.
Level.ToString(), ref First);
160 if (this.collectOnEventId)
163 if (this.collectOnObject)
166 if (this.collectOnActor)
169 if (this.collectOnFacility)
172 if (this.collectOnModule)
175 string Key = sb.ToString();
177 if (!this.eventCache.
TryGetValue(Key, out Rec Rec))
181 First = Event.Timestamp
184 this.eventCache[Key] = Rec;
187 Rec.Events.
Add(Payload);
192 this.synchObj.Release();
199 private static void Append(StringBuilder sb,
string Value, ref
bool First)
212 public DateTime First;
213 public DateTime Last;
218 await this.synchObj.WaitAsync();
222 Dictionary<string, object> Payload =
new Dictionary<string, object>()
224 {
"First", Rec.First },
225 {
"Last", Rec.Last },
226 {
"Count", Rec.Events.Count },
227 {
"Collect",
new Dictionary<string, object>()
229 {
"OnType", this.collectOnType },
230 {
"OnLevel", this.collectOnLevel },
231 {
"OnEventId", this.collectOnEventId },
232 {
"OnObject", this.collectOnObject },
233 {
"OnActor", this.collectOnActor },
234 {
"OnFacility", this.collectOnFacility },
235 {
"OnModule", this.collectOnModule }
238 {
"Events", Rec.Events.ToArray() }
245 Event Event =
new Event(
EventType.Critical, ex,
this.ObjectID,
string.Empty,
string.Empty,
246 EventLevel.Minor,
string.Empty,
string.Empty);
253 this.synchObj.Release();
Static class managing encoding and decoding of internet content.
static Task< ContentResponse > PostAsync(Uri Uri, object Data, params KeyValuePair< string, string >[] Headers)
Posts to a resource, using a Uniform Resource Identifier (or Locator).
Class representing an event.
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.
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.
Base class for event sinks.
virtual string ObjectID
Object ID, used when logging events.
Event sink sending events to a remote service using POST.
void UpdateCertificate(X509Certificate Certificate)
Updates the certificate used in mTLS negotiation.
WebHookEventSink(string ObjectID, string CallbackUrl, X509Certificate Certificate, int MaxSecondsUsed, int MaxSecondsUnused, bool CollectOnType, bool CollectOnLevel, bool CollectOnEventId, bool CollectOnObject, bool CollectOnActor, bool CollectOnFacility, bool CollectOnModule)
Event sink sending events to a remote service using POST.
WebHookEventSink(string ObjectID, string CallbackUrl)
Event sink sending events to a remote service using POST.
WebHookEventSink(string ObjectID, string CallbackUrl, X509Certificate Certificate)
Event sink sending events to a remote service using POST.
override async Task Queue(Event Event)
Queues an event to be output.
override Task DisposeAsync()
IDisposableAsync.DisposeAsync()
Implements an in-memory cache.
void Dispose()
IDisposable.Dispose
bool TryGetValue(KeyType Key, out ValueType Value)
Tries to get a value from the cache.
void Add(KeyType Key, ValueType Value)
Adds an item to the cache.
void Clear()
Clears the cache.
Event arguments for cache item removal events.
ValueType Value
Value of item that was removed.
A chunked list is a linked list of chunks of objects of type T .
Interface for Mutual TLS (mTLS) Clients or TLS servers.