IKVM11  11
Java SE 11 Virtual Machine for .NET
Loading...
Searching...
No Matches
TextDiagnosticFormatter.cs
Go to the documentation of this file.
1using System;
2using System.Buffers;
3using System.Text;
4
7
9{
10
14 class TextDiagnosticFormatter : DiagnosticChannelFormatter<TextDiagnosticFormatterOptions>
15 {
16
22 base(options)
23 {
24
25 }
26
28 protected override void WriteImpl(in DiagnosticEvent @event, IDiagnosticChannel channel)
29 {
30 var encoding = channel.Encoding ?? Encoding.UTF8;
31 using var buffer = MemoryPool<byte>.Shared.Rent(65535);
32 var writer = new MemoryBufferWriter<byte>(buffer.Memory);
33 TextDiagnosticFormat.Write(@event.Diagnostic.Id, @event.Diagnostic.Level, @event.Diagnostic.Message, @event.Args, @event.Exception, @event.Location, ref writer, encoding);
34 WriteLine(writer, encoding);
35 channel.Writer.Write(buffer, writer.WrittenCount);
36 }
37
43 void WriteLine(MemoryBufferWriter<byte> writer, Encoding encoding)
44 {
45 var buf = (Span<byte>)stackalloc byte[8];
46 var len = encoding.GetBytes(Environment.NewLine, buf);
47 writer.Write(buf[..len]);
48 }
49
50 }
51
52}
Implements the IBufferWriter<T> interface around a Memory<T>.
Handles writing diagnostic events to text output.
static void Write(int id, DiagnosticLevel level, string message, object?[] args, Exception? exception, DiagnosticLocation location, TextWriter writer)
Writes the given event data to the specified StringWriter.
Handles writing diagnostic events to text output.
TextDiagnosticFormatter(TextDiagnosticFormatterOptions options)
Initializes a new instance.
override void WriteImpl(in DiagnosticEvent @event, IDiagnosticChannel channel)
void Write(IMemoryOwner< byte > memory, int length)
Enqueues the specified memory to the diagnostic channel.
Handles consuming and outputting diagnostic events.
IDiagnosticChannelWriter Writer
Gets the writer that allows you to enqueue data to the channel.