IKVM11  11
Java SE 11 Virtual Machine for .NET
Loading...
Searching...
No Matches
FormattedDiagnosticHandler.cs
Go to the documentation of this file.
1using System;
2
4
6{
7
11 class FormattedDiagnosticHandler : DiagnosticEventHandler, IDisposable
12 {
13
14 readonly string _spec;
15 readonly DiagnosticFormatterProvider _formatters;
16 readonly IDiagnosticFormatter _formatter;
17
24 {
25 _spec = spec ?? throw new ArgumentNullException(nameof(spec));
26 _formatters = formatters ?? throw new ArgumentNullException(nameof(formatters));
27 _formatter = _formatters.GetFormatter(spec) ?? throw new InvalidOperationException("Cannot find formatter for specification.");
28 }
29
31 public override bool IsEnabled(Diagnostic diagnostic)
32 {
33 return true;
34 }
35
37 public override void Report(in DiagnosticEvent @event)
38 {
39 if (IsEnabled(@event.Diagnostic))
40 _formatter.Write(@event);
41 }
42
43 public virtual void Dispose()
44 {
45 if (_formatter is IDisposable disposable)
46 disposable.Dispose();
47 }
48
49 }
50
51}
Provides the capability to look up diagnostic channels.
IDiagnosticHandler implementation that outputs based on a format specification.
FormattedDiagnosticHandler(string spec, DiagnosticFormatterProvider formatters)
Initializes a new instance.
override bool IsEnabled(Diagnostic diagnostic)
Returns true if the specified Diagnostic is enabled.