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;
3using System.Threading.Tasks;
4using Waher.Events;
6
8{
12 public abstract class ConsoleCustomWriter : WorkItem
13 {
14 private readonly ConsoleColor? foregroundColor;
15 private readonly ConsoleColor? backgroundColor;
16
22 public ConsoleCustomWriter(ConsoleColor? ForegroundColor, ConsoleColor? BackgroundColor)
23 {
24 this.foregroundColor = ForegroundColor;
25 this.backgroundColor = BackgroundColor;
26 }
27
32 public override sealed async Task Execute(CancellationToken Cancel)
33 {
34 try
35 {
36 ConsoleColor FgBak = System.Console.ForegroundColor;
37 ConsoleColor BgBak = System.Console.BackgroundColor;
38
39 if (this.foregroundColor.HasValue)
40 System.Console.ForegroundColor = this.foregroundColor.Value;
41
42 if (this.backgroundColor.HasValue)
43 System.Console.BackgroundColor = this.backgroundColor.Value;
44
45 await this.DoWrite();
46
47 System.Console.ForegroundColor = FgBak;
48 System.Console.BackgroundColor = BgBak;
49 }
50 catch (Exception ex)
51 {
52 Log.Exception(ex);
53 }
54 }
55
59 protected abstract Task DoWrite();
60
61 }
62}
Static class managing the application event log. Applications and services log events on this static ...
Definition: Log.cs:14
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:1657
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(CancellationToken Cancel)
Executes the console operation.
Represents an asynchronous operation to be performed.
Definition: WorkItem.cs:10