public void TextOptions() { var options = new ZLoggerOptions() { PrefixFormatter = (writer, info) => ZString.Utf8Format(writer, "[Pre:{0}]", info.LogLevel), SuffixFormatter = (writer, info) => ZString.Utf8Format(writer, "[Suf:{0}]", info.CategoryName), ExceptionFormatter = (writer, ex) => ZString.Utf8Format(writer, "{0}", ex.Message) }; var processsor = new TestProcessor(options); var loggerFactory = LoggerFactory.Create(x => { x.SetMinimumLevel(LogLevel.Debug); x.AddZLoggerLogProcessor(processsor); }); var logger = loggerFactory.CreateLogger("test"); logger.ZLogDebug("FooBar{0}-NanoNano{1}", 100, 200); processsor.Dequeue().Should().Be("[Pre:Debug]FooBar100-NanoNano200[Suf:test]"); logger.ZLogInformation("FooBar{0}-NanoNano{1}", 100, 300); processsor.Dequeue().Should().Be("[Pre:Information]FooBar100-NanoNano300[Suf:test]"); // fallback case logger.LogDebug("FooBar{0}-NanoNano{1}", 100, 200); processsor.Dequeue().Should().Be("[Pre:Debug]FooBar100-NanoNano200[Suf:test]"); logger.LogInformation("FooBar{0}-NanoNano{1}", 100, 300); processsor.Dequeue().Should().Be("[Pre:Information]FooBar100-NanoNano300[Suf:test]"); }
public void FormatUtf8(IBufferWriter <byte> writer, ZLoggerOptions options, Utf8JsonWriter?jsonWriter) { var str = formatter(state, exception); if (options.EnableStructuredLogging && jsonWriter != null) { options.StructuredLoggingFormatter.Invoke(jsonWriter, this.LogInfo); jsonWriter.WriteString(options.MessagePropertyName, str); jsonWriter.WriteNull(options.PayloadPropertyName); } else { options.PrefixFormatter?.Invoke(writer, this.LogInfo); var memory = writer.GetMemory(Encoding.UTF8.GetMaxByteCount(str.Length)); if (MemoryMarshal.TryGetArray <byte>(memory, out var segment) && segment.Array != null) { var written1 = Encoding.UTF8.GetBytes(str, 0, str.Length, segment.Array, segment.Offset); writer.Advance(written1); } options.SuffixFormatter?.Invoke(writer, this.LogInfo); if (this.LogInfo.Exception != null) { options.ExceptionFormatter(writer, this.LogInfo.Exception); } } }
public RollingFileStream(Func <DateTimeOffset, int, string> fileNameSelector, Func <DateTimeOffset, DateTimeOffset> timestampPattern, int rollSizeKB, ZLoggerOptions options) { this.timestampPattern = timestampPattern; this.fileNameSelector = fileNameSelector; this.rollSizeInBytes = rollSizeKB * 1024; this.options = options; ValidateFileNameSelector(); TryChangeNewRollingFile(); }
public LogGUIProcessor(LogGUI logGUI, ZLoggerOptions options) { this.logGUI = logGUI; this.options = options; }
public static IServiceCollection AddDFrameHosting(this IServiceCollection services, ZLoggerOptions zLoggerOptions) { services.AddSingleton <ExecuteService>(); services.AddSingleton <ISummaryService, SummaryService>(); services.AddSingleton <ILoggingService, LoggingService>(); services.AddSingleton <IStatisticsService <AbStatistic>, AbStatisticsService>(); services.AddSingleton <IStatisticsService <Statistic>, StatisticsMockService>(); services.AddSingleton <IWorkersService, WorkersService>(); services.AddSingleton <LogProcessorOptions>(new LogProcessorOptions() { LoggerOptions = zLoggerOptions, }); return(services); }
public void OverloadCheck() { var options = new ZLoggerOptions() { ExceptionFormatter = (writer, ex) => { } }; var processsor = new TestProcessor(options); var loggerFactory = LoggerFactory.Create(x => { x.SetMinimumLevel(LogLevel.Debug); x.AddZLoggerLogProcessor(processsor); }); var logger = loggerFactory.CreateLogger("test"); logger.ZLogDebug("foo"); processsor.EntryMessages.Dequeue().Should().Be("foo"); logger.ZLogDebug(new EventId(10), "foo"); processsor.EntryMessages.Dequeue().Should().Be("foo"); logger.ZLogDebug(new Exception(), "foo"); processsor.EntryMessages.Dequeue().Should().Be("foo"); logger.ZLogDebug(new EventId(10), new Exception(), "foo"); processsor.EntryMessages.Dequeue().Should().Be("foo"); logger.ZLogDebug("foo {0}", "bar"); processsor.EntryMessages.Dequeue().Should().Be("foo bar"); logger.ZLogDebug(new EventId(10), "foo {0}", "bar"); processsor.EntryMessages.Dequeue().Should().Be("foo bar"); logger.ZLogDebug(new Exception(), "foo {0}", "bar"); processsor.EntryMessages.Dequeue().Should().Be("foo bar"); logger.ZLogDebug(new EventId(10), new Exception(), "foo {0}", "bar"); processsor.EntryMessages.Dequeue().Should().Be("foo bar"); logger.ZLogDebugWithPayload(new { Foo = 999 }, "foo"); processsor.EntryMessages.Dequeue().Should().Be("foo"); logger.ZLogDebugWithPayload(new EventId(10), new { Foo = 999 }, "foo"); processsor.EntryMessages.Dequeue().Should().Be("foo"); logger.ZLogDebugWithPayload(new Exception(), new { Foo = 999 }, "foo"); processsor.EntryMessages.Dequeue().Should().Be("foo"); logger.ZLogDebugWithPayload(new EventId(10), new Exception(), new { Foo = 999 }, "foo"); processsor.EntryMessages.Dequeue().Should().Be("foo"); logger.ZLogDebugWithPayload(new { Foo = 999 }, "foo {0}", "bar"); processsor.EntryMessages.Dequeue().Should().Be("foo bar"); logger.ZLogDebugWithPayload(new EventId(10), new { Foo = 999 }, "foo {0}", "bar"); processsor.EntryMessages.Dequeue().Should().Be("foo bar"); logger.ZLogDebugWithPayload(new Exception(), new { Foo = 999 }, "foo {0}", "bar"); processsor.EntryMessages.Dequeue().Should().Be("foo bar"); logger.ZLogDebugWithPayload(new EventId(10), new Exception(), new { Foo = 999 }, "foo {0}", "bar"); processsor.EntryMessages.Dequeue().Should().Be("foo bar"); logger.ZLog(LogLevel.Debug, "foo"); processsor.EntryMessages.Dequeue().Should().Be("foo"); logger.ZLog(LogLevel.Debug, new EventId(10), "foo"); processsor.EntryMessages.Dequeue().Should().Be("foo"); logger.ZLog(LogLevel.Debug, new Exception(), "foo"); processsor.EntryMessages.Dequeue().Should().Be("foo"); logger.ZLog(LogLevel.Debug, new EventId(10), new Exception(), "foo"); processsor.EntryMessages.Dequeue().Should().Be("foo"); logger.ZLog(LogLevel.Debug, "foo {0}", "bar"); processsor.EntryMessages.Dequeue().Should().Be("foo bar"); logger.ZLog(LogLevel.Debug, new EventId(10), "foo {0}", "bar"); processsor.EntryMessages.Dequeue().Should().Be("foo bar"); logger.ZLog(LogLevel.Debug, new Exception(), "foo {0}", "bar"); processsor.EntryMessages.Dequeue().Should().Be("foo bar"); logger.ZLog(LogLevel.Debug, new EventId(10), new Exception(), "foo {0}", "bar"); processsor.EntryMessages.Dequeue().Should().Be("foo bar"); logger.ZLogWithPayload(LogLevel.Debug, new { Foo = 999 }, "foo"); processsor.EntryMessages.Dequeue().Should().Be("foo"); logger.ZLogWithPayload(LogLevel.Debug, new EventId(10), new { Foo = 999 }, "foo"); processsor.EntryMessages.Dequeue().Should().Be("foo"); logger.ZLogWithPayload(LogLevel.Debug, new Exception(), new { Foo = 999 }, "foo"); processsor.EntryMessages.Dequeue().Should().Be("foo"); logger.ZLogWithPayload(LogLevel.Debug, new EventId(10), new Exception(), new { Foo = 999 }, "foo"); processsor.EntryMessages.Dequeue().Should().Be("foo"); logger.ZLogWithPayload(LogLevel.Debug, new { Foo = 999 }, "foo {0}", "bar"); processsor.EntryMessages.Dequeue().Should().Be("foo bar"); logger.ZLogWithPayload(LogLevel.Debug, new EventId(10), new { Foo = 999 }, "foo {0}", "bar"); processsor.EntryMessages.Dequeue().Should().Be("foo bar"); logger.ZLogWithPayload(LogLevel.Debug, new Exception(), new { Foo = 999 }, "foo {0}", "bar"); processsor.EntryMessages.Dequeue().Should().Be("foo bar"); logger.ZLogWithPayload(LogLevel.Debug, new EventId(10), new Exception(), new { Foo = 999 }, "foo {0}", "bar"); processsor.EntryMessages.Dequeue().Should().Be("foo bar"); }
public TestProcessor(ZLoggerOptions options) { this.options = options; }
public UnityDebugLogProcessor(ZLoggerOptions options) { this.options = options; }