Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
DebugEventSink.cs
1using System.Collections.Generic;
2using System.Text;
3using System.Threading.Tasks;
4
5namespace Waher.Events
6{
11 {
12 private const int TabWidth = 8;
13
18 : base("Debug Event Sink")
19 {
20 }
21
25 public override Task Queue(Event Event)
26 {
27 StringBuilder Output = new StringBuilder();
28 int i;
29
30 switch (Event.Type)
31 {
32 case EventType.Debug:
33 Output.Append("DEBUG: ");
34 break;
35
36 case EventType.Informational:
37 Output.Append("INFO: ");
38 break;
39
40 case EventType.Notice:
41 Output.Append("NOTICE: ");
42 break;
43
44 case EventType.Warning:
45 Output.Append("WARNING: ");
46 break;
47
48 case EventType.Error:
49 Output.Append("ERROR: ");
50 break;
51
52 case EventType.Critical:
53 Output.Append("CRITICAL: ");
54 break;
55
56 case EventType.Alert:
57 Output.Append("ALERT: ");
58 break;
59
60 case EventType.Emergency:
61 Output.Append("EMERGENCY: ");
62 break;
63 }
64
65 if (!string.IsNullOrEmpty(Event.EventId))
66 {
67 Output.Append(Event.EventId);
68 Output.Append(": ");
69 }
70
71 if (Event.Message.IndexOf('\t') >= 0)
72 {
73 string[] Parts = Event.Message.Split('\t');
74 bool First = true;
75
76 foreach (string Part in Parts)
77 {
78 if (First)
79 First = false;
80 else
81 {
82 i = Output.ToString().Length % TabWidth;
83 Output.Append(new string(' ', TabWidth - i));
84 }
85
86 Output.Append(Part);
87 }
88 }
89 else
90 Output.Append(Event.Message);
91
92 Output.AppendLine();
93 Output.Append(" ");
94
95 this.AddTag(Output, "Timestamp", Event.Timestamp.ToString(), true);
96 this.AddTag(Output, "Level", Event.Level.ToString(), false);
97
98 if (!string.IsNullOrEmpty(Event.Object))
99 this.AddTag(Output, "Object", Event.Object, false);
100
101 if (!string.IsNullOrEmpty(Event.Actor))
102 this.AddTag(Output, "Actor", Event.Actor, false);
103
104 if (!string.IsNullOrEmpty(Event.Facility))
105 this.AddTag(Output, "Facility", Event.Facility, false);
106
107 if (!string.IsNullOrEmpty(Event.Module))
108 this.AddTag(Output, "Module", Event.Module, false);
109
110 if (!(Event.Tags is null) && Event.Tags.Length > 0)
111 {
112 foreach (KeyValuePair<string, object> P in Event.Tags)
113 this.AddTag(Output, P.Key, P.Value, false);
114 }
115
116 Output.AppendLine();
117
118 System.Diagnostics.Debug.WriteLine(Output.ToString());
119
120 return Task.CompletedTask;
121 }
122
123 private void AddTag(StringBuilder Output, string Key, object Value, bool First)
124 {
125 if (!First)
126 Output.Append(", ");
127
128 Output.Append(Key);
129 Output.Append('=');
130 Output.Append(Value);
131 }
132
133 }
134}
Outputs events to the console standard output.
override Task Queue(Event Event)
IEventSink.Queue
DebugEventSink()
Outputs events to the console standard output.
Class representing an event.
Definition: Event.cs:10
string Message
Free-text event message.
Definition: Event.cs:131
EventType Type
Type of event.
Definition: Event.cs:121
string Object
Object related to the event.
Definition: Event.cs:136
EventLevel Level
Event Level.
Definition: Event.cs:126
string Actor
Actor responsible for the action causing the event.
Definition: Event.cs:141
string Module
Module where the event is reported.
Definition: Event.cs:156
DateTime Timestamp
Timestamp of event.
Definition: Event.cs:116
KeyValuePair< string, object >[] Tags
Variable set of tags providing event-specific information.
Definition: Event.cs:166
string EventId
Computer-readable Event ID identifying type of even.
Definition: Event.cs:146
string Facility
Facility can be either a facility in the network sense or in the system sense.
Definition: Event.cs:151
Base class for event sinks.
Definition: EventSink.cs:9
EventType
Type of event.
Definition: EventType.cs:7