public AsyncStreamLineMessageWriter(Stream stream, ZLoggerOptions options)
        {
            this.newLine = Encoding.UTF8.GetBytes(Environment.NewLine);
            if (newLine.Length == 1)
            {
                // cr or lf
                this.newLine1 = newLine[0];
                this.newLine2 = default;
                this.crlf     = false;
            }
            else
            {
                // crlf(windows)
                this.newLine1 = newLine[0];
                this.newLine2 = newLine[1];
                this.crlf     = true;
            }

            this.options = options;
            this.stream  = stream;
            this.channel = Channel.CreateUnbounded <IZLoggerEntry>(new UnboundedChannelOptions
            {
                AllowSynchronousContinuations = false, // always should be in async loop.
                SingleWriter = false,
                SingleReader = true,
            });
            this.writeLoop = Task.Run(WriteLoop);
        }
示例#2
0
        public static string FormatToString(this IZLoggerEntry entry, ZLoggerOptions options, Utf8JsonWriter?jsonWriter)
        {
            var boxedBuilder = (IBufferWriter <byte>)ZString.CreateUtf8StringBuilder();

            try
            {
                entry.FormatUtf8(boxedBuilder, options, jsonWriter);
                return(boxedBuilder.ToString() !);
            }
            finally
            {
                ((Utf8ValueStringBuilder)boxedBuilder).Dispose();
            }
        }