public void Log <TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func <TState, Exception, string> formatter) { if (!IsEnabled(logLevel)) { return; } if (formatter != null) { LogHistory.Add(formatter(state, exception)); } else { if (state != null) { LogHistory.Add($"{DateTime.Now:s} [{logLevel.ToString()}]: {state}"); } if (exception != null) { LogHistory.Add($"{DateTime.Now:s} [{logLevel.ToString()}] Exception Details: {exception.ToString().PadLeft(512, ' ').Substring(0, 511)}"); } } //cleanup LogHistory if (LogHistory.Count > 9999) { for (var i = 0; i < 1000; i++) { LogHistory.RemoveAt(0); } } }