您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 

37 行
949 B

  1. using System;
  2. using System.Collections.Generic;
  3. using Microsoft.Extensions.Logging;
  4. namespace Cap.Consistency.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. }