IKVM11  11
Java SE 11 Virtual Machine for .NET
Loading...
Searching...
No Matches
FileDiagnosticChannelFactory.cs
Go to the documentation of this file.
1using System;
2using System.IO;
3using System.Linq;
4using System.Text;
5
6using Microsoft.Extensions.DependencyInjection;
7
9{
10
15 {
16
17 public const string STDOUT = "stdout";
18 public const string STDERR = "stderr";
19
25 public static IServiceCollection Add(IServiceCollection services)
26 {
27 return services.AddSingleton<IDiagnosticChannelFactory, FileDiagnosticChannelFactory>();
28 }
29
31 public IDiagnosticChannel? CreateChannel(string spec)
32 {
33 if (spec is null)
34 throw new ArgumentNullException(nameof(spec));
35
36 return spec switch
37 {
38 "1" or STDOUT => new StreamDiagnosticChannel(Console.OpenStandardOutput(), Console.OutputEncoding, leaveOpen: false),
39 "2" or STDERR => new StreamDiagnosticChannel(Console.OpenStandardError(), Console.OutputEncoding, leaveOpen: false),
40 _ when spec.Contains(Path.DirectorySeparatorChar) => new StreamDiagnosticChannel(File.OpenWrite(spec), Encoding.UTF8, leaveOpen: false),
41 _ => null,
42 };
43 }
44
45 }
46
47}
IDiagnosticChannel? CreateChannel(string spec)
Attempts to parse the channel spec into a IDiagnosticChannel
static IServiceCollection Add(IServiceCollection services)
Adds the JSON diagnostic formater to the IServiceCollection.
Implementation of IDiagnosticChannel that writes encoded text to a PipeWriter.
Handles consuming and outputting diagnostic events.