選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 

40 行
1005 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. {
  15. LogMessages.Add(state?.ToString());
  16. return null;
  17. }
  18. public bool IsEnabled(LogLevel logLevel)
  19. {
  20. return true;
  21. }
  22. public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception,
  23. Func<TState, Exception, string> formatter)
  24. {
  25. if (formatter == null)
  26. {
  27. LogMessages.Add(state.ToString());
  28. }
  29. else
  30. {
  31. LogMessages.Add(formatter(state, exception));
  32. }
  33. }
  34. }
  35. }