You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

37 lines
948 B

  1. using System;
  2. using System.Collections.Generic;
  3. using Microsoft.Extensions.Logging;
  4. namespace DotNetCore.CAP.Test
  5. {
  6. public interface ITestLogger
  7. {
  8. IList<string> LogMessages { get; }
  9. }
  10. public class TestLogger<TName> : ILogger<TName>, ITestLogger
  11. {
  12. public IList<string> LogMessages { get; } = new List<string>();
  13. public IDisposable BeginScope<TState>(TState state) {
  14. LogMessages.Add(state?.ToString());
  15. return null;
  16. }
  17. public bool IsEnabled(LogLevel logLevel) {
  18. return true;
  19. }
  20. public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter) {
  21. if (formatter == null) {
  22. LogMessages.Add(state.ToString());
  23. }
  24. else {
  25. LogMessages.Add(formatter(state, exception));
  26. }
  27. }
  28. }
  29. }