Example #1
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();
            }
        }
 public void Post(IZLoggerEntry log)
 {
     channel.Writer.TryWrite(log);
 }
Example #3
0
        private static void WriteEntry(IZLoggerEntry entry)
        {
            var boxedBuilder = (IBufferWriter <byte>) new Utf8ValueStringBuilder(false);

            try
            {
                entry.FormatUtf8(boxedBuilder, options, null);

                var message = boxedBuilder.ToString();

                var marker = message.IndexOf("====");

                if (marker >= 0)
                {
                    var content = message.Substring(marker + 5);
                    if (content.StartsWith("RCV"))
                    {
                        var uid = UID128.Parse(content.Substring(4, 22));
                        _perCompilationStatus[uid] = CompilationStatus.Pending;
                    }
                    else if (content.StartsWith("BEGIN"))
                    {
                        _currentUID = UID128.Parse(content.Substring(6, 22));
                        _perCompilation[_currentUID]       = new ConcurrentQueue <LogMessage>();
                        _perCompilationStatus[_currentUID] = CompilationStatus.OnGoing;
                    }
                    else if (content.StartsWith("SUCCESS"))
                    {
                        _perCompilationStatus[_currentUID] = CompilationStatus.Success;
                        _currentUID = default;
                    }
                    else if (content.StartsWith("FAIL"))
                    {
                        _perCompilationStatus[_currentUID] = CompilationStatus.Fail;
                        _currentUID = default;
                    }
                    else if (content.StartsWith("ABORT"))
                    {
                        _perCompilationStatus[_currentUID] = CompilationStatus.Fail;
                        _currentUID = default;
                    }
                    else if (content.StartsWith("CANCELED"))
                    {
                        _perCompilationStatus[_currentUID] = CompilationStatus.Fail;
                        _currentUID = default;
                    }
                }
                else
                {
                    if (_currentUID.IsNotNull())
                    {
                        _perCompilation[_currentUID].Enqueue(new LogMessage()
                        {
                            Message   = message,
                            Timestamp = entry.LogInfo.Timestamp.ToUnixTimeMilliseconds(),
                            LogLevel  = entry.LogInfo.LogLevel
                        });
                    }
                }
            }
            finally
            {
            }
        }