public void ConvertWithoutPrefixes()
        {
            JsonToUtf8BytesFormatter formatter = new JsonToUtf8BytesFormatter(new LogEventJsonConverterOptions()
            {
                JsonOptions = new JsonSerializerOptions {
                    WriteIndented = true
                }
            });

            var bytes = formatter.GetBytes(new LogEvent(DateTimeOffset.Now, LogEventLevel.Warning,
                                                        new Exception("test"), new MessageTemplate("qwe", new MessageTemplateToken[0]), fo));

            Assert.True(bytes.Length > 0);
            this.output.WriteLine(Encoding.UTF8.GetString(bytes));
        }
Exemplo n.º 2
0
        public void Utf8Json()
        {
            byte[] result = null;
            JsonToUtf8BytesFormatter formatter = new JsonToUtf8BytesFormatter(new LogEventJsonConverterOptions());

            GC.Collect();
            GC.Collect();
            GC.Collect();
            GC.WaitForFullGCComplete();
            long      memory1   = GC.GetTotalMemory(true);
            Stopwatch stopwatch = Stopwatch.StartNew();

            for (int i = 0; i < 10000; i++)
            {
                result = formatter.GetBytes(logEvent);
                Assert.True(result.Length > 0);
            }

            this.output.WriteLine(stopwatch.ElapsedMilliseconds.ToString("F"));
            this.output.WriteLine(result.Length.ToString("D"));
            this.output.WriteLine((GC.GetTotalMemory(false) - memory1).ToString("D"));
            this.output.WriteLine(Encoding.UTF8.GetString(result));
        }