IKVM11  11
Java SE 11 Virtual Machine for .NET
Loading...
Searching...
No Matches
JsonDiagnosticFormatter.cs
Go to the documentation of this file.
1using System;
2using System.Buffers;
3using System.Text;
4
7
9{
10
14 class JsonDiagnosticFormatter : DiagnosticChannelFormatter<JsonDiagnosticFormatterOptions>
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 JsonDiagnosticFormat.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 return;
37 }
38
44 void WriteLine(MemoryBufferWriter<byte> writer, Encoding encoding)
45 {
46 var buf = (Span<byte>)stackalloc byte[8];
47 var len = encoding.GetBytes(Environment.NewLine, buf);
48 writer.Write(buf[..len]);
49 }
50
51 }
52
53}
Implements the IBufferWriter<T> interface around a Memory<T>.
Formats diagnostic events into a stream of JSON objects.
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.
Formats diagnostic events into a stream of JSON objects.
override void WriteImpl(in DiagnosticEvent @event, IDiagnosticChannel channel)
JsonDiagnosticFormatter(JsonDiagnosticFormatterOptions options)
Initializes a new instance.
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.