6using System.Threading.Tasks;
32 var buffer = MemoryPool<byte>.Shared.Rent(65535);
37 Write(
id, level, message, args, exception, location,
ref wrt, writer.Encoding);
38 writer.Write(writer.Encoding.GetString(buffer.Memory.Span[..wrt.WrittenCount]));
59 var buffer = MemoryPool<byte>.Shared.Rent(65535);
64 Write(
id, level, message, args, exception, location,
ref wrt, writer.Encoding);
65 await writer.WriteAsync(writer.Encoding.GetString(buffer.Memory.Span[..wrt.WrittenCount]));
86 where TWriter : IBufferWriter<
byte>
89 WriteDiagnosticEvent(
ref encoder,
id, level, message, args, exception, location);
104 where TWriter : IBufferWriter<byte>
106 WriteDiagnosticLocation(
ref writer, location);
107 WriteDiagnosticLevel(
ref writer, level);
109 WriteDiagnosticCode(
ref writer,
id);
111 WriteDiagnosticMessage(
ref writer, message, args);
120 where TWriter : IBufferWriter<byte>
124 if (location.Path !=
null)
126 writer.Write(location.Path);
130 if (location.StartLine > 0)
134 if (location.StartColumn > 0)
136 if (location.EndColumn > 0)
138 if (location.EndLine > 0)
140 writer.Write($
"({location.StartLine},{location.StartColumn},{location.EndLine},{location.EndColumn})");
144 writer.Write($
"({location.StartLine},{location.StartColumn}-{location.EndColumn})");
149 writer.Write($
"({location.StartLine},{location.StartColumn})");
152 else if (location.EndLine > 0)
154 writer.Write($
"({location.StartLine}-{location.EndLine})");
158 writer.Write($
"({location.StartLine})");
173 where TWriter : IBufferWriter<byte>
175 writer.Write(level
switch
177 DiagnosticLevel.Trace =>
"trace",
178 DiagnosticLevel.Info =>
"info",
179 DiagnosticLevel.Warning =>
"warning",
180 DiagnosticLevel.Error =>
"error",
181 DiagnosticLevel.Fatal =>
"fatal",
182 _ =>
throw new InvalidOperationException(),
192 where TWriter : IBufferWriter<byte>
194 writer.Write(
"IKVM");
196 writer.Write($
"{code:D4}");
198 var buf = (Span<char>)stackalloc
char[16];
199 if (code.TryFormat(buf, out var l,
"D4") ==
false)
200 throw new InvalidOperationException();
202 writer.Write(buf[..l]);
213 where TWriter : IBufferWriter<byte>
215 writer.Write(
string.Format(
null, message, args));
Implements the IBufferWriter<T> interface around a Memory<T>.
Handles writing diagnostic events to text output.
static void Write< TWriter >(int id, DiagnosticLevel level, string message, object?[] args, Exception? exception, DiagnosticLocation location, ref TWriter writer, Encoding? encoding=null)
Writes the given event data to the specified IBufferWriter<byte>.
static async ValueTask WriteAsync(int id, DiagnosticLevel level, string message, object?[] args, Exception? exception, DiagnosticLocation location, TextWriter writer, CancellationToken cancellationToken)
Writes the given event data to the specified StringWriter.
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.
readonly struct DiagnosticLocation(string Path, int StartLine, int StartColumn, int EndLine, int EndColumn)
Describes the location of a diagnostic event.
DiagnosticLevel
Represents the level of security of a diagnostic event.
Provides an interface to write text to a IBufferWriter<byte>.