Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
ConsoleCustomWriter.cs
1using System;
2using System.Threading.Tasks;
3using Waher.Events;
4
6{
10 public abstract class ConsoleCustomWriter : WorkItem
11 {
12 private readonly ConsoleColor? foregroundColor;
13 private readonly ConsoleColor? backgroundColor;
14
20 public ConsoleCustomWriter(ConsoleColor? ForegroundColor, ConsoleColor? BackgroundColor)
21 {
22 this.foregroundColor = ForegroundColor;
23 this.backgroundColor = BackgroundColor;
24 }
25
29 public override sealed async Task Execute()
30 {
31 try
32 {
33 ConsoleColor FgBak = System.Console.ForegroundColor;
34 ConsoleColor BgBak = System.Console.BackgroundColor;
35
36 if (this.foregroundColor.HasValue)
37 System.Console.ForegroundColor = this.foregroundColor.Value;
38
39 if (this.backgroundColor.HasValue)
40 System.Console.BackgroundColor = this.backgroundColor.Value;
41
42 await this.DoWrite();
43
44 System.Console.ForegroundColor = FgBak;
45 System.Console.BackgroundColor = BgBak;
46 }
47 catch (Exception ex)
48 {
49 Log.Exception(ex);
50 }
51 }
52
56 protected abstract Task DoWrite();
57
58 }
59}
Static class managing the application event log. Applications and services log events on this static ...
Definition: Log.cs:13
static void Exception(Exception Exception, string Object, string Actor, string EventId, EventLevel Level, string Facility, string Module, params KeyValuePair< string, object >[] Tags)
Logs an exception. Event type will be determined by the severity of the exception.
Definition: Log.cs:1647
Abstract base class for custom writers
ConsoleCustomWriter(ConsoleColor? ForegroundColor, ConsoleColor? BackgroundColor)
Abstract base class for custom writers
abstract Task DoWrite()
Method that does the actual custom writing.
override sealed async Task Execute()
Executes the console operation.
Manages a Console operation.
Definition: WorkItem.cs:9